I have a computer on the local network, behind a NAT router. I have some 192.168.0.x addresses, but I really want to know my public IP address, not something mentioned in
How to get the IP address of the server on which my C# application is running on?
or
How to get the IP address of a machine in C#
I need C# code.
Is it possible? If so, how?
I do it like this: I create a class that holds the geo location data
then I use the following code to call the geo data and fill the class.
as the answer is "bad" xml one needs to specify the xRoot element or one gets an error.
Happy coding
Walter
After some search, and by expanding my requirements, I found out that this will get me not only the IP, but GEO-location as well:
XML returned, and thus key/value dictionary will be filled as such:
And for convenience, return class:
The problem is that the IP address you're looking for doesn't belong to your computer. It belongs to your NAT router. The only ways I can think of getting it is to use an external server or have some way of querying your router.
If your router supports SNMP, you may be able to get it that way.
I prefer http://icanhazip.com. It returns a simple text string. No HTML parsing required.
If you are worried about connection lose or the availability of the site, you can also try this way to avoid that issue by including above suggestions.
Hope this one also help.
I believe you really need to connect with some server to get your external IP.