DelphiFAQ Home Search:

Detect your own IP Address

 

comments6 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

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;
You don't like the formatting? Check out SourceCoder then!

Comments:

2006-04-24, 02:02:22
anonymous from United States  
hi
2006-07-04, 12:49:14
anonymous from United Kingdom  
hi
2006-07-17, 08:08:55
anonymous from Brazil  
rating
Well done!!!
2007-01-11, 15:23:22   (updated: 2007-01-11, 15:29:45)
anonymous from Thailand  
it always returns 127.0.0.1
2007-10-08, 02:13:41
anonymous from Singapore, Singapore  
great
2008-09-08, 05:16:40
anonymous from United States  
test

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.