Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 17670, Get the IP address of the machine

by Danny Heijl Email: Anonymous


How to get the DNS name and the IP address(es) of the machine your program runs on, using standard socket API calls.
Download Details
FTP  download also available 0 bytes
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 5.0  to 6.0 18 downloads
Copyright: No significant restrictions


Size: 0 bytes
Updated on Thu, 14 Mar 2002 13:22:16 GMT
Originally uploaded on Thu, 14 Mar 2002 13:21:58 GMT
Description
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;

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Server Response from: ETNACDC03