Discussion:
My ip address
(too old to reply)
Richard Bibby
2008-07-19 18:42:41 UTC
Permalink
Hej,

Is there a good way to find my internal IP address, and also my external ip
address programically?

Many thanks.

/Richard
Jamie Dale
2008-07-19 21:24:34 UTC
Permalink
The only reliable way to get your external IP address (Router or modem) of
your PC or network is to make a http call to a server which will tell you.

EG - whatismyip.com have a page where you can make automated http requests
and the server will simply give you the IP as a response with no other code:

The address is:
http://www.whatismyip.com/automation/n09230945.asp

You will simply get one line of text which will be the external IP.

To get the internal IP is a bit more fiddly as it depends on how many
network cards you have in the machine (and thats only one issue). Most
people use Winsock APIs to get it but I'm not sure how well that works with
multiple NICs. Also Indy has an IPWatch component which I think will give
you internal IP information.

Good luck

JD
Post by Richard Bibby
Hej,
Is there a good way to find my internal IP address, and also my external
ip address programically?
Many thanks.
/Richard
Remy Lebeau (TeamB)
2008-07-20 07:20:33 UTC
Permalink
Post by Richard Bibby
Is there a good way to find my internal IP address, and also
my external ip address programically?
Determining your internal IP address(es) is easy. The winsock gethostname()
and gethostbyname() functions, or the Win32 API GetAdaptersInfo() function,
can return all available IPs for the machine. If the machine is directly
connected to the Internet modem, then one of the IPs will also be your
external IP. However, if you are behind a router, then the only reliable
way to get the external IP is to query an external server for it, such as
http://iplookup.flashfxp.com or similar site.


Gambit
Richard Bibby
2008-07-20 18:28:04 UTC
Permalink
Hej,

Thanks for the information.

Which indy component should I use to call the web site?

/Richard
Post by Remy Lebeau (TeamB)
Post by Richard Bibby
Is there a good way to find my internal IP address, and also
my external ip address programically?
Determining your internal IP address(es) is easy. The winsock
gethostname() and gethostbyname() functions, or the Win32 API
GetAdaptersInfo() function, can return all available IPs for the machine.
If the machine is directly connected to the Internet modem, then one of
the IPs will also be your external IP. However, if you are behind a
router, then the only reliable way to get the external IP is to query an
external server for it, such as http://iplookup.flashfxp.com or similar
site.
Gambit
Jamie Dale
2008-07-20 22:33:25 UTC
Permalink
Post by Richard Bibby
Hej,
Thanks for the information.
Which indy component should I use to call the web site?
TIdHTTP does quite a good job ;)
Remy Lebeau (TeamB)
2008-07-21 06:34:13 UTC
Permalink
Post by Richard Bibby
Which indy component should I use to call the web site?
TIdHTTP. And you can use Indy's GStack.LocalAddresses list to get the
calling machine's IP addresses.


Gambit

Continue reading on narkive:
Loading...