Get IP Address

Started by
6 comments, last by TheBluMage 19 years, 4 months ago
Hi, is there anyway to find out the external IP address of a computer on a network? I'd prefer not to use a third-party IP getter site, as there is no guarantee that it will be up and running. I'm using C++/CLI, so anything in the Win32 API or .NET Framework is available to my program. I don't mind jumping through a bunch of hoops or doing some low-level router communication or something like that, I just want it to all be handled by the host machine/networking equipment without any outside help. Thanks in advance!
Advertisement
There is no way to know other than to ask a computer outside your internal network to find out what IP address your network is masquerading as.

In fact, there's no gaurantee that someone outside your network knows the actual IP you're using.

I've seen ISPs that actually NAT their users behind a few IP addresses.

So even if you find a way to talk to the local router, there might be even more routers beyond that one.
Hmmm, that's disappointing. I'm writing a client/server for a small P2P network, and so I guess the next question I'll ask is what do the other P2P networks do for users behind routers? (IE, a host behind a router wants to respond to a query that was made several hops away and the response packet should have the responder's IP address in it so the other user can connect directly.)
You can ask any other peer on the network 'what's my IP'? And they can send the apparent source IP back to the orginating host. It's possible, though very unlikely that different peers would get a different IP address if multiple NAT gatewats where used (the only scenario I can think of would be NAT4-NAT6 gateways).
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Original versions of, for example, gnutella (the only client I know anything about) didn't.

I remember getting queries from 192.168.0.103. From across the internet.

I'm sure new clients have some tricks, like asking other p2p clients what IP address this client appears to be coming from.
I guess I can try and work with that - was trying not to make any changes to the protocol. I seem to remember reading somewhere about a way to check the path that IP packets go through to get from one place to another. I can't remember the specifics, but maybe one of you guys knows what I'm talking about and can tell me whether that would get the address I'm looking for. Thanks.
Quote:Original post by TheBluMage
I guess I can try and work with that - was trying not to make any changes to the protocol. I seem to remember reading somewhere about a way to check the path that IP packets go through to get from one place to another. I can't remember the specifics, but maybe one of you guys knows what I'm talking about and can tell me whether that would get the address I'm looking for. Thanks.


I guess you're talking about what traceroute (tracert on windows) does.
You could perform a traceroute (which uses the ICMP protocol, which may or may not be blocked by a firewall) and assume that the first address that doesn't start with 10. or 192.168. is your external IP address. However, that's not guaranteed to work due to various reasons.

Like a previous poster pointed out, the best way is to ask a computer "on the internet" about your ip address (and port).
Thanks - that's what I was thinking of. Thanks for your help and ideas all!

This topic is closed to new replies.

Advertisement