4

I am aware of the NetworkChange.NetworkAddressChanged event, but that is only for the local network interfaces.

What is the best way to detect the public IP address of the gateway has changed? Presumably one has to do it by polling an external reliable address, such a google.com...?

Lara
  • 163
  • 2
  • 9
  • Polling sounds like it would be the best way to go. Possibly poll/scrape a site like "whatismyip.com"... – Jemes May 31 '11 at 04:03

3 Answers3

1

Here's one by Akamai: http://whatismyip.akamai.com/

Erik Osterman
  • 559
  • 4
  • 7
1

If the router supports it, you could use SNMP to query for its public IP address (or, at least, when I tried to do this I had to query for all IP addresses and filter out the private address(es)). You'll need to identify the OIDs (object IDs) that correspond to the IP address values, which I believe should be the same across all routers. Poll the router at regular intervals and compare the previous result to the current result. Alternatively, set up an SNMP Trap so the router will notify your application of a change in IP address. It might take more work to implement than simply processing the HTML from a "what is my IP" website, but this will be more efficient, possibly more reliable, won't generate any WAN traffic, and you won't have to rely on a website you don't control that could break your application by blocking you or changing the structure of their HTML.

#SNMP is an open source SNMP library for .NET.

Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
0

Using an external API is the only reliable method. Most of them who reveals your IP address will block a machine made request and ask for a CAPTCHA input. Here is a good one which allows machines to make request:

http://ip.nefsc.noaa.gov

Xaqron
  • 29,931
  • 42
  • 140
  • 205
  • 1
    Unfortunately, this link doesn't work anymore, it returns "Sorry, there is nothing to see here" – dcastro Jan 07 '15 at 16:43