Windows – Query a Windows DHCP server : find MAC from hostname

command-line-interfacedhcpmac addresswindows

From my computer, I want to query my DHCP server to find a specific mac adress.
I want to enter the hostname to search, and getting back the Mac address.

Something like :

netsh dhcp server scope show clients |find hostname

This command line doesn't works, but maybe you have some tips ?

Thank you,

Best Answer

If you are comfortable with Powershell, this script will help you find what you need: https://sites.google.com/site/assafmiron/ServerScripts/get-dhcpleases

This script almost works as well. It currently lists extra clients. Some regex magic with the find command parameters could fix this. Save to to a .cmd file and specify your dhcppserver and a valid scope.

for /f "skip=4 delims=: tokens=2" %%a in ('nslookup %1') do set IP=%%a
netsh dhcp server \\ourdhcpsvr scope 192.168.1.0 show clients|findstr "%IP%"

Output should look like this

172.16.19.78 - 255.255.248.0 - c6-33-5f-cb-a7-a5 -4/25/2017 8:26:07 AM -D