Getting the "External" IP?

Anyone know how I can get the external IP address of my machine? Like NOT 10.0.0.x or 192.168.0.x?

Thanks!
Psylord
PsylordAsked:
Who is Participating?
 
AvonWyssConnect With a Mentor Commented:
If you need all addresses of your machine (the computer itself does not make a difference between private and public addresses), you can do it with some code like this:


var
     Buf: array[0..1023] of Char;
        Current: ^PInAddr;


     gethostname(@Buf,SizeOf(Buf));
     Current:=Pointer(gethostbyname(@Buf).h_addr_list);
        while Assigned(Current^) do begin
                WriteLn(inet_ntoa(Current^^));
                Inc(Current);
        end;


Note that very similar code can be used to retrieve all machine names (using the h_name and h_aliases members of the PHostEnt).
0
 
PsylordAuthor Commented:
Yes but how do I decalare this "^PInAddr"?

0
 
PsylordAuthor Commented:
If you can show me how to declare this I will still give you the points... If it works. :)
0
 
AvonWyssCommented:
PInAddr is declared in WINSOCK, and ^PInAddr is a pointer to a TInAddr pointer. The code works as I posted it (tested)!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.