EDIT the selected answer solves the broader problem that I was trying to solve, which is "Given selected mac addresses, how do I efficiently find each mac addresses corresponding IP address on the local network?".

ORIGINAL: I need to write a program to find out the IP addresses of machines on my local network.

I have the mac address of the machines.

Given that DHCP servers return the same IP address for a given mac address, would it be possible somehow to send a DHCP request to the server, insert the known mac address, and capture the response, which presumably has the correct IP address in it for that mac address?

FURTHER INFORMATION: I tried arpwatch and found it to be unreliable. Much more satisfactory was addrwatch https://github.com/fln/addrwatch

  • 1
    ping all of them from the same host in their network, and do arp -a. – Rui F Ribeiro Feb 19 '18 at 16:34
  • @RuiFRibeiro Thanks for the comment, apart from the comment not answering the question, I'm looking for an immediate response to my request for the correct IP address - how long would it take to ping the address range? – Duke Dougal Feb 19 '18 at 16:39
  • ARPs do not do routing; you might go to the leases file if the machines are using DHCP; the other option is locating them via the switch command line. Actually, if you have several machines with the same MAC address the best course of action is getting down to business combing MAC address lists on switches. I used to have all that on a DB. – Rui F Ribeiro Feb 19 '18 at 16:45
  • 1
    It would certainly be possible to spoof a DHCP request, but depending on how your switches are set up, either you or the real host will get the answer. I also don't know any program to do this easily. Another option is to try broadcast ping (ping -b), but not all hosts answer those. If you have a home router, a third option is to ask it for MAC-to-IP mappings if the router supports it (some do via UPNP). – dirkt Feb 19 '18 at 16:47
  • 1
    arpwatch if you have time to wait – roaima Feb 19 '18 at 17:53
arp-scan -l

Manual page for arp-scan(1). (If your machine has multiple interfaces, you may need to specify which interface's network you wish to scan with -I <interface>.)

  • This doesn't answer the question as asked. (Given a little more scripting it could...) – roaima Feb 19 '18 at 20:03
  • @roaima, this answers the problem described in the first sentence of the post; it does not answer the question in the title. Given the mismatch between the two, I assumed XY (perhaps incorrectly) and tried to answer the question that seemed to actually state what the OP was trying to accomplish. – user4556274 Feb 19 '18 at 21:28
  • Actually this is exactly what I have been searching for over the past couple of days. I can write some code to make use of this answer. This does not answer the question in the title but does solve my overall problem, which is to efficiently find the IP addresses of mac addresses on a local network. Thanks. – Duke Dougal Feb 19 '18 at 22:09
  • Also solving my problem in a different way is arpwatch mentioned above by @roaima Thanks. – Duke Dougal Feb 19 '18 at 22:39

If you know the MAC address, you can construct the link-local IPv6 address from it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.