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:
|
unit LocalIPs_Unit;
interface
uses
Windows, Classes, WinSock;
procedure GetLocalIPs(List: TStrings);
implementation
// -----------------------------------------------------------------------------
procedure GetLocalIPs(List: TStrings);
type
PPInAddr = ^PInAddr;
var
wsaData: TWSAData;
HostInfo: PHostEnt;
HostName: array[0..255] of Char;
Addr: PPInAddr;
VersionRequested: Word;
begin
List.Clear;
// WinSock Version muss höher als 1.1 sein
VersionRequested := MakeWord(2, 1);
if WSAStartup(VersionRequested, wsaData) <> 0 then
Exit;
try
if gethostname(HostName, SizeOf(HostName)) <> 0 then
Exit;
HostInfo := gethostbyname(HostName);
if HostInfo = nil then
Exit;
Addr := Pointer(HostInfo^.h_addr_list);
if (Addr = nil) or (Addr^ = nil) then
Exit;
List.Add(inet_ntoa(Addr^^));
inc(Addr);
while Addr^ <> nil do
begin
List.Add(inet_ntoa(Addr^^));
inc(Addr);
end; {end while}
finally
WSACleanup;
end; {end try/finally}
end; {end procedure}
// -----------------------------------------------------------------------------
end.
|