Sep 3, 2002 #1 delphidestructor Programmer Joined Oct 20, 2000 Messages 67 Can anyone tell me if it is possible to retrieve the local IP(s) from a system programmatically? Thanks in advance. Mike
Can anyone tell me if it is possible to retrieve the local IP(s) from a system programmatically? Thanks in advance. Mike
Sep 4, 2002 #2 Nordlund Programmer Joined Jul 17, 2001 Messages 458 Location SE Yep... The first (and maybe the easiest) way is to download the Indy package (http://www.nervrona.com/indy) 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; Upvote 0 Downvote
Yep... The first (and maybe the easiest) way is to download the Indy package (http://www.nervrona.com/indy) 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;