Query a Windows DHCP server : find MAC from hostname
42,711
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
Related videos on Youtube
Author by
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
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,
-
jscott about 12 yearsIf you remove the
|find hostname
, what error messages do you receive? I can see two issues: 1.) You're not specifying the dhcp server name/IP,netsh dhcp server \\servername
... 2.) You're not specifying which scope you want:netsh dhcp server \\servername scope 10.130.40.0 show clients
.
-
-
Reg Edit about 7 yearsThe question is "find MAC from hostname" but this does NOT show MAC.
-
Reg Edit about 7 yearsThe question is "find MAC from hostname" but your script does NOT show MAC. And the linked script gives a screenful of errors as soon as you load it into PS.
-
uSlackr about 7 yearsI confirmed that the script does indeed display the MAC address. I added the output to my answer. Most scripts (like the one I linked) require some tweaking for your environment. Did you try? Why do you feel the need to trash a 5 year old answer when the OP confirmed it met he/her needs?
-
Reg Edit about 7 yearsWhat version of Windows are you running it on? Because the script just hung when I ran it. Tried both Win 10 and Server 2016. The netsh bit on its own doesn't show MAC address for me. I don't want other people to waste time like I did on something that doesn't work. Perhaps it did on an old version of Windows?
-
uSlackr about 7 yearsWindows 10 works. Did you run it as admin?