Examples Delphi

Note: If you run through NAT then your public address can only be told by someone else like: http://www.myip.dk/

uses
WinSock; // type PHostEnt
function My_IP_Address : longint;
var
buf : array [0..255] of char;
RemoteHost : PHostEnt;
begin
Winsock.GetHostName(@buf, 255);
RemoteHost:=Winsock.GetHostByName(buf);
if RemoteHost=NIL then
My_IP_Address := winsock.htonl($07000001) { 127.0.0.1 }
else
My_IP_Address := longint(pointer(RemoteHost^.h_addr_list^)^);
Result := Winsock.ntohl(Result);
end;