Solved

Getting the "External" IP?

Posted on 2001-06-10
4
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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