Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get mac address from IP using DHCP?

I am trying to create scripts/services that allow for waking PCs in a windows domain via WOL. Now i want to give the user the option to select an AD container as a starting point for the waking of PCs contained within. My initial thought is using DHCP as a repository to query for MAC addresses given the hostnames (which i can easily enough pull from AD given the container).

Is there a way to programmatically query the DHCP service/server, passing hostnames and recover the associated MAC addresses?

Or, is there a better/easier way to solve my problem?

like image 730
Matt Kocaj Avatar asked Oct 14 '25 16:10

Matt Kocaj


2 Answers

This is a little bit wacky it seems that there's no way to query the DHCP server programmatically. Thanks cottsak for asking the question. I understand that the DHCP protocol doesn't have such a query, but I thought mayb the executable from Microsoft might have some way you can address it from the command line. I haven't heard anybody anywhere say that there is no such case, but it must be so.

WHOA, wait a minute... I think I found what we're looking for: NETSH. cf:

http://social.technet.microsoft.com/Forums/en/ITCG/thread/afb4be16-09bd-4260-b515-8323d85d4ccb

Where it says if you open a command prompt on the DHCP server you can run this command:

netsh dhcp server scope 192.168.1.0 show clients

and get a report such as this:

10.10.98.53 - 255.255.255.0 -00-0c-29-02-a4-09 - NEVER EXPIRES -D 10.10.98.54 - 255.255.255.0 - 00-22-19-10-29-75 -1/21/2012 8:39:25 AM -D

Yippeee! Thanks for the thread!! If it wasn't for this one, I enver would have narrowed my search to technet adn found that one.

like image 134
Friends of the Penguin Avatar answered Oct 17 '25 06:10

Friends of the Penguin


Try dhcpexim.exe from microsoft.

or, if you prefer using pure C. DhcpEnumSubnetClientsV4

like image 31
J-16 SDiZ Avatar answered Oct 17 '25 06:10

J-16 SDiZ