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 off
setlocal EnableDelayedExpansion
if exist "%TEMP%\dhcpMAC.TM1" del /q "%TEMP%\dhcpMAC.TM1"
set srv=N
set srvkey=HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
for /f "Tokens=3" %%a in ('reg query %srvkey% /V dhcpNameServer^|find /i "dhcpNameServer"') do (
 set srv=\\%%a
)
if "%srv%" EQU "N" goto nodhcp
for /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=