Sign in to follow this  

Get IP Address

This topic is 4749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 4749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this