Mirror

Detect your own IP Address (Views: 100)


Problem/Question/Abstract:

Detect your own IP Address

Answer:

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;

<< Back to main page