1

I am scanning for IPs on my local network, and one of the pieces of information I wish to receive when an IP is found is whether that IP is static or dynamic. So far, the closest question to mine that I have found only addresses checking your own machine. Here is my function:

    private bool isDynamic()
    {
        NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
        int currentSocketIndex = (new IPPacketInformation()).Interface;

        bool isDynamic = adapters[currentSocketIndex].GetIPProperties().GetIPv4Properties().IsDhcpEnabled;
        return isDynamic;
    }

I would like to modify this so that it can take an IP address, connect to the device that the IP belongs to (if it exists and does not block the connection), and determine whether that machine's IP is static/dynamic. At the moment, my function only checks my machine.

Could anyone point me in the right direction? I can't find references for doing something like this, but I doubt that it's impossible.

Garrett
  • 13
  • 4
  • 5
    you can't find anything about it because that is impossible if you do not have access to the router – Denis Schaf Mar 18 '19 at 14:40
  • 3
    Do you know the range of addresses used for the DHCP pool? If so, you could just find addresses outside of that and assume they're static. I think WMI can also tell you if it's dynamic, if the clients are all Windows and you have that kind of access. – itsme86 Mar 18 '19 at 14:41
  • @itsme86 (some?) routers can reserve static address from the DHCP pool. – stuartd Mar 18 '19 at 14:48
  • WMI can indeed do this - check the DHCPEnabled property of the [Win32_NetworkAdapterConfiguration](https://learn.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-networkadapterconfiguration) class. But, you need to run the WMI query as an account that has the right to connect as an admin. – stuartd Mar 18 '19 at 14:51
  • @stuartd So that would mean that using WMI requires that I have each machine's specific admin account credientials? – Garrett Mar 18 '19 at 14:56
  • @stuartd Reserved DHCP addresses are different than static addresses. Static addresses are specified by the host/client, reserved DHCP addresses are still given by the server. Some people still call reserved IPs "static" which I guess is true in a sense, just not the fundamental sense. – itsme86 Mar 18 '19 at 14:59
  • @Garrett If they're domain-joined computers, you can just use your domain credentials if your domain account is an administrator on the computers. – itsme86 Mar 18 '19 at 15:00
  • to defeat the DHCP server you need to become the DHCP server and check who accepts your Addresses – Denis Schaf Mar 18 '19 at 15:00
  • @itsme86 ah yes that makes sense :) thanks. Our router calls them "static leases", which I think confused me. – stuartd Mar 18 '19 at 15:01
  • @itsme86 Gotcha. This is part of an application which will eventually run on many different networks so I may just have to forego this feature. Many thanks for the help! – Garrett Mar 18 '19 at 15:20
  • Do you just want to know that the client has the IP you're expecting? Or do you want to know if the client's software is configured to request the same IP from the DHCP server? – Patrick Tucci Mar 18 '19 at 15:25
  • @PatrickTucci Probably the latter? I mainly just need to know whether the IP is subject to change in the future. – Garrett Mar 18 '19 at 15:27

1 Answers1

0

You can't find anything about it because that is impossible if you do not have access to the router. You can only find that by asking the router, which will most likely not tell you or require a router-specific request/protocol to tell you. Or you can ask the device directly which will not tell you whether its IP is static or dynamic unless you install an application on that machine that will answer your request. Some operating systems might provide this kind of service (like WMI on windows) already but you will never be able to tell for every network device.

BUT:

If you have a lot of time you can listen to the DHCP/BootP traffic and find you dynamic devices like this because dynamic devices will frequently refresh their session

A DIFFERENT APPROACH:

New idea but dangerous to do in important networks and I do not recommend it at all: Start your own DHCP server and start giving away addresses and see who accepts them then set them back. Please note that this could cause a HUGE amount of damage in company networks for example.

Denis Schaf
  • 2,478
  • 1
  • 8
  • 17
  • Interesting. I didn't think it'd be impossible to check a machine for whether DHCP is enabled or not. That'd explain why I haven't found any information on the topic. – Garrett Mar 18 '19 at 14:48
  • you can listen on port 67/68 to broadcast messages and hope for traffic and catch some communication but it will not be relyable – Denis Schaf Mar 18 '19 at 14:50
  • @DenisSchaf not reliable indeed, you would have to wait for a full DCHP renewall timeout in order to gather useful information and depending on the enviroment it could be a huge time. Better going WMI if they are windows machines. – Cleptus Mar 18 '19 at 15:04
  • even if this isn't the answer you were hoping for I think this is the correct one – Denis Schaf Mar 19 '19 at 12:10