Solved

Getting the "External" IP?

Posted on 2001-06-10
4
264 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now