Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving local IP's

Status
Not open for further replies.

delphidestructor

Programmer
Oct 20, 2000
67
Can anyone tell me if it is possible to retrieve the local IP(s) from a system programmatically? Thanks in advance. Mike
 
Yep... The first (and maybe the easiest) way is to download the Indy package (
or, you can try this example...
Be sure to add WinSock in the uses clause...


function GetClientIP: String;
var
pht : PHostEnt;
tempPChar : array[0..100] of Char;
IPAddress : String;
begin
IPAddress := '0.0.0.0';

try
if gethostname( tempPChar, 100 ) = 0 then begin
pht := gethostbyname ( tempPChar );
IPAddress := IntToStr( byte( pht^.h_addr_list^[0] ) ) + '.' +
IntToStr( byte( pht^.h_addr_list^[1] ) ) + '.' +
IntToStr( byte( pht^.h_addr_list^[2] ) ) + '.' +
IntToStr( byte( pht^.h_addr_list^[3] ) );
end;
except end;
Result := IPAddress;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top