Search code examples
cmddhcp

Extracting information from DHCP client list


Usually when I access my router settings by entering the IP Adress in my browser I can access a list of all clients connected to my network. Is there a way to retrieve this information somehow and export it to a .txt file or to Excel? I tried some CMD code but in vain.

Thanks a lot.


Solution

  • There is the arp command. It lists addresses, that are known to the computer. Which basically means, "there was some communication to/from this address since last reset (explicit reset or reboot)". But it doesn't tell you, whether the address is currently reachable. So to get reachable addresses, you have to delete arp's cache, force communication with every address (a ping is sufficient) and then show the cache:

    @echo off
    arp -d
    (for /l %%i in (1,1,255) DO start /min ping 192.168.1.%%i -n 1) & timeout 10 >nul 
    arp -a | find "dynamic"
    

    The timeout gives time to finish the pings and for arp to build it's cache data.

    Be sure to adapt the base address (192.168.1.) to your needs. If you use a non-English version of Windows, you also have to adapt the string dynamic.

    The start /min makes the pings quite effective by running them parallel.

    Note: some computers/devices may not respond to ping, so they would be missing in the list.

    Bonus line:

    for /f %%a in ('arp -a^|find "dynam"') do for /f "tokens=2,3 delims=[] " %%b in ('ping -a -n 1 %%a^|find "["') do echo %%c %%b
    

    (again, that's for the English version. Adapt the tokens for other languages; for a German Windows, it's tokens=5,6)