[阅读: 535] 2005-01-05 13:44:08
The following code is not dependent on Windows 2000 or Active directory, will
list all IP addresses of the interfaces of the (IPV4) host it runs on, and
is portable to Linux as it uses standard socket calls:
uses WinSock;
....
{ lists all IP-address assigned to this host }
const
MAXHOSTNAMELEN = 256;
var
HostName: string;
pHE: PHostEnt;
pAddr: ^PChar;
begin
{ get hostname }
SetLength(HostName, MAXHOSTNAMELEN);
GetHostName(Pointer(HostName), MAXHOSTNAMELEN);
SetLength(HostName, StrLen(Pointer(HostName)));
{ host name }
ShowMessage(HostName);
{ get list of ip adresses }
pHE := GetHostByName(Pointer(HostName));
{ host name again}
ShowMessage(pHE.h_name);
{ lenght of an IP address, 4 = IPV4 }
ShowMessage(IntToStr(pHE.h_length));
{ list all adresses }
pAddr := Pointer(pHE.h_addr);
while PChar(pAddr^) <> Nil do
begin
ShowMessage(inet_ntoa(in_addr(pAddr^)));
inc(pAddr);
end;
end;