简体   繁体   中英

How do I programatically get the IP address I am NATed behind? (i.e my pulic IP)

I want to get the IP address I am being NATed behind (eg the one presented to the outside world, rather than my local IP).

Something like the result you get from www.ipchicken.com.

How can I get this? The local IP info is easy to find, but I have no idea how to go about getting the IP assigned from the ISP.

The reason I need it is that my network infrastructure is such that I have two gateways out of the network. If one fails, it trips over transparently to the other. All well and good, but there is no alerting mechanism to tell me that I have failed over.

I believe it's quite hard to get this information. I guess another approach I could take is by putting a webservice on an externally hosted webserver - the idea being that it returns the IP of the querying host. (However, I have no idea how to do this either!) I suspect this might be the easiest way to go.

Your computer does not have access to this information locally; you need to get it from one of the many network services which do this.

There are lot's of ip services

This one, for example. Just make a GET request and parce a simple html : http://checkip.dyndns.org/

Some more details about this service (Policies and rules): http://dyn.com/support/developers/checkip-tool/

upd If you need to check your IP frequently you'd better to add your own web-service. .dyndns.org allows to check the ip once for 10 minutes.

You can run some .net code on web-service:

((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();

But I think a script language (python?) will be more suitable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM