Getting notified of IP address change?

  • Thread starter Thread starter roger beniot
  • Start date Start date
R

roger beniot

I would like to figure out how to detect an IP address change for an
XP/Win2K3 machine that is leasing an IP via DHCP (and do it in C#)...

Is there any event that indicates an IP address change?... I really
don't want to poll for a change.

I would like to get an event indicating the IP address has changed and
propogate that change to other levels of my app.

If anyone has a solution that isn't in C# I am interested in that as
well (but I would really like to know if it is possible in C#).

Thanks in advance,
Roger
 
Yes, but it will require some PInvoke calls, the core API to call is NotifyAddrChange (iphlpapi.dll), please consult the IP HELPER
docs (platform SDK) for more info .

Willy.
 
Good stuff thanks Willy... So that covers the case when a machine,
connected to the same network as the dhcp server, gets a newly
assigned IP address...

Now how about the case when you have a LAN that is behind a Gateway
and the gateway has a leased IP address... Is there a way to figure
out if the gateways ip address has changed (besides polling).

I have used the WMI stuff (specifically ManagementObject) to query for
the DefaultIPGateway successfully, but now my only option seems to
keep polling the field for a change.

thanks in advance,
roger
 
Create a .net remoting service on the gateway that uses the pinvoke to get
the ip update as Willy said. Then, that service can notify any client with
..NET using events or a remoting host on the client, etc. No polling needed.
Just curious, why would the clients need to be notified of the gateway
change? If for public host address, then just have the service above,
change the DNS host record after the pinvoke event, then clients should pick
up the new IP after TTL.
 
Back
Top