Solved

Getting the "External" IP?

Posted on 2001-06-10
4
274 Views
Last Modified: 2010-04-06
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
Comment
Question by:Psylord
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
AvonWyss earned 50 total points
ID: 6176204
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
 

Author Comment

by:Psylord
ID: 6176284
Yes but how do I decalare this "^PInAddr"?

0
 

Author Comment

by:Psylord
ID: 6176286
If you can show me how to declare this I will still give you the points... If it works. :)
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6176303
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multiple image collision 13 88
Wincontrol not (correctly) drawn 15 48
Way to create an iPhone app for my customers 8 46
Using MMsystem To change audio input 1 19
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question