3

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

8
  • 1
    ping all of them from the same host in their network, and do arp -a. Commented Feb 19, 2018 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 10.0.0.0 address range? Commented Feb 19, 2018 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. Commented Feb 19, 2018 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
    Commented Feb 19, 2018 at 16:47
  • 1
    arpwatch if you have time to wait Commented Feb 19, 2018 at 17:53

3 Answers 3

3
#!/bin/bash
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>.)

4
  • This doesn't answer the question as asked. (Given a little more scripting it could...) Commented Feb 19, 2018 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. Commented Feb 19, 2018 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. Commented Feb 19, 2018 at 22:09
  • Also solving my problem in a different way is arpwatch mentioned above by @roaima Thanks. Commented Feb 19, 2018 at 22:39
2

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

1

Over a simple network, this command works.

arp -a | grep [macaddress]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .