Question

I want to retrieve IP address of my computer (same as I get on http://www.whatsmyip.org/) I have a win32 project.

This is the code that I am using, as I didnt find any tutorial on this, I could get following info, but not the IP address which I saw for my computer on the whatsmyip.org :(

The IP I got on whatsmyip.org starts with 116.x.x.x

enter image description here

Was it helpful?

Solution

Your code gets adapter addresses, which are local. If you want your Internet address, you need to use the Internet, not your local network. You need to replicate the functionality of asking an external site what IP it sees you connecting from. See here for some suggestions for how to do that.

Retrieving http://icanhazip.com will do it. You can use whatever HTTP library you like.

OTHER TIPS

The IP which assigned to your machine is not necessarily the IP that you see outside of your local network (e.g. in whatsmyip.org).

Your machine is not directly connected to the Internet with a valid and static IP. Maybe you are behind a NAT. So you can not determine your valid IP over Internet by listing your local assigned IPs in many situations.

To findout what IP address you have in Internet, you can do two ways. Ask from someone over Internet (for example, using whatsmyip.org). Or, query your local network recursivly (which is not easy task)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top