3

How do I get my externally visible IP address?

None of the answers so far have worked for me. My application will not be connected to anything at the time, and I need it to display the IP address to the user.

Is there any way to do this?

Thanks, I've decided just to parse a whatismyip website. Much easier.

Christian Stewart
  • 15,217
  • 20
  • 82
  • 139
  • 4
    What do you mean "global" IP address? – Jon Apr 24 '11 at 22:45
  • 1
    I'll bet he means his externally-visible (from the other side of any NAT) IP address. – Michael Petrotta Apr 24 '11 at 22:47
  • See this answer http://stackoverflow.com/questions/66363/get-external-ip-address-over-remoting-in-c/1319527#1319527 – Bala R Apr 24 '11 at 22:48
  • 1
    @MichaelPetrotta: Could be, but he has to be more specific. Keep in mind that any system can have *many* IP addresses, it can also have IPv6 addresses, etc. The question really needs clarification. – Jon Apr 24 '11 at 22:53
  • @Jon: Yep. It's one of those simple things, like why you can't use floats for money, why `string != same_string` in many languages, that very few people intuitively get. – Michael Petrotta Apr 24 '11 at 22:55
  • Hey, I would be fine with scraping a website for the IP, just unsure what website has the ip as the only thing on the page. – Christian Stewart Apr 24 '11 at 23:06
  • @Christian, can you explain what you mean by *"None of the answers so far have worked for me"*? There are some good answers in the linked questions. Clearly, you have Internet access; otherwise, your scraping suggestion wouldn't work. What, exactly, is not working for you? – Michael Petrotta Apr 24 '11 at 23:09

3 Answers3

1

See this question here: How to get *internet* IP? (assuming that you're on a local network and want to get your external/internet ip)

Community
  • 1
  • 1
Teoman Soygul
  • 25,584
  • 6
  • 69
  • 80
1

Depends on what you mean.

If you're running an ASP.NET application and want to get the address of the host to which the request was sent, you can do so here:

Request.ServerVariables["LOCAL_ADDR"];

If you want to directly get information about a network interface on the host (be it from within ASP.NET or any .NET application context), take a look at the IPAddressInformation class. Specifically, the Address property.

That latter link has some sample code on how to use it. There's a lot of information you can obtain about a network interface aside from just it's IP.

David
  • 208,112
  • 36
  • 198
  • 279
1

At one time I had a script that basically downloaded the html content from http://www.whatismyip.com/ and parsed through the page to extract the ip address. This may not be the best way to do it but it worked for me.

Cole W
  • 15,123
  • 6
  • 51
  • 85