-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowLocalIp.pas
67 lines (56 loc) · 1.18 KB
/
ShowLocalIp.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
unit ShowLocalIp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, winsock;
type
TLocalIpForm = class(TForm)
OKBtn: TButton;
IpEdit: TLabeledEdit;
procedure OKBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
LocalIpForm: TLocalIpForm;
implementation
// Finder din lokale IPv4 adresse
function GetLocalIP: string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array [0..63] of Ansichar;
i: Integer;
GInitData: TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(Buffer);
if phe = nil then
Exit;
pptr := PaPInAddr(phe^.h_addr_list);
i := 0;
while pptr^[i] <> nil do
begin
Result := string(inet_ntoa(pptr^[i]^));
Inc(i);
end;
WSACleanup;
end;
{$R *.dfm}
procedure TLocalIpForm.OKBtnClick(Sender: TObject);
begin
Close;
end;
procedure TLocalIpForm.FormActivate(Sender: TObject);
begin
IpEdit.Text:=GetLocalIp;
end;
end.