Can I determine the current IP from a known MAC Address?

后端 未结 7 420
难免孤独
难免孤独 2021-02-01 03:06

I have a shell script which uses etherwake to wake up a machine on my local network. After the machine is awake, I\'m not sure of the IP address.

While trying to answer

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 03:40

    I don't think there is a single command to do this. One hack would be to do a ping scan or a broadcast ping on the subnet and then query the arp table for the IP address of the MAC address. Obviously not an ideal solution. Example:

    nmap -sP 192.168.1.0/24 >/dev/null && arp -an | grep  | awk '{print $2}' | sed 's/[()]//g'
    

    Here nmap will do a ping scan and populate your arp cache. Once the scan is done, the arp command can be used to print the arp table and then you pull out the IP address with grep/awk. You could try replacing nmap with a broadcast ping, but that probably isn't as reliable.

提交回复
热议问题