Arcite
Arcite

Reputation: 212

How to find DHCP lease information from an arbitrary client?

I am writing Win32 API (C++) code to query a network for certain information. One of those pieces of information is the DHCP lease end time. I was able to get most of the information I needed from the GetIpNetTable (and/or GetIpNetTable2) functions; but after loads of Google, MSDN, Stackoverflow searches I cannot find a way of getting all of the lease information from an arbitrary client (this code does not run on the server). I'm familiar with the GetAdaptersInfo function but that only retrieves information for the current machine, not all machines on the network. Does anyone know of a way to map out all of the DHCP lease information of a network from an arbitrary client?

Upvotes: 3

Views: 964

Answers (1)

Ton Plooij
Ton Plooij

Reputation: 2641

You could do this by implementing a read-only DHCP server. The clients will send out a DHCPDISCOVER message as a broadcast (on UDP port 67) which you can receive. The responding DHCP server will broadcast back the DHCPOFFER including the client's MAC address, relevant IP information and the lease time. If the client accepts these settings it will now broadcast a DHCPREQUEST message so your read-only server will know the client will (try to) use the DHCPOFFER information. You can't see the DHPCACK acknowledge from the server but if things fail for the client it will send a new DHCPDISCOVER. This way you can build a table of DHCP information including lease times for local clients.

Upvotes: 1

Related Questions