• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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
0
Psylord
Asked:
Psylord
  • 2
  • 2
1 Solution
 
AvonWyssCommented:
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now