JSI Tip 10200. How can I display all the MAC addresses on my DHCP enabled network?

Jerold Schulman

February 27, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Using the Netsh.exe utility, and the technique from tip 10130, I have scripted dhcpMAC.bat to return all the MAC address of DHCP clients on my network.

The dhcpMAC.bat batch script requires no parameters. It MUST be run from a DHCP client. To redirect the MAC addresses to a file, use dhcpMAC>FileName.

dhcpMAC.bat contains:

@echo offsetlocal EnableDelayedExpansionif exist "%TEMP%dhcpMAC.TM1" del /q "%TEMP%dhcpMAC.TM1"set srv=Nset srvkey=HKLMSYSTEMCurrentControlSetServicesTcpipParametersfor /f "Tokens=3" %%a in ('reg query %srvkey% /V dhcpNameServer^|find /i "dhcpNameServer"') do ( set srv=\%%a)if "%srv%" EQU "N" goto nodhcpfor /f "tokens=1" %%a in ('netsh dhcp server %srv% show scope^|find /i "Active"') do ( set scope=%%a for /f "tokens=3-8 Delims=-" %%b in ('netsh dhcp server %srv% scope !scope! show clients^|find " -D"') do (  set MAC=%%b-%%c-%%d-%%e-%%f-%%g  set MAC=!MAC: =!  @echo !MAC!>>"%TEMP%dhcpMAC.TM1" ) for /f "tokens=3-8 Delims=-" %%b in ('netsh dhcp server %srv% scope !scope! show clientsv5^|find " -D"') do (  set MAC=%%b-%%c-%%d-%%e-%%f-%%g  set MAC=!MAC: =!  @echo !MAC!>>"%TEMP%dhcpMAC.TM1" ))sort "%TEMP%dhcpMAC.TM1" /O "%TEMP%dhcpMAC.TM2"del /q "%TEMP%dhcpMAC.TM1"set /p prev=


Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like