Can I determine the current IP from a known MAC Address?
参考 https://stackoverflow.com/questions/13552881/can-i-determine-the-current-ip-from-a-known-mac-address
-
最佳实践,通过nmap扫描来获取局域网中所有存活的ip,然后向每个ip发送一次ping请求,从而更新 arp 缓存表,然后 通过命令:arm -n 来获取mac地址和ip的映射关系
-
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 <mac address here> | 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.
-
nmap 扫描结果:
Starting Nmap 6.40 ( http://nmap.org ) at 2023-09-25 14:03 CST
Nmap scan report for 10.0.11.1
Host is up (0.0010s latency).
MAC Address: 8C:68:3A:63:34:7C (Unknown)
Nmap scan report for 10.0.11.11
Host is up (-0.100s latency).
MAC Address: 2C:9D:1E:C1:97:4A (Unknown)
Nmap scan report for 10.0.11.14
Host is up (-0.099s latency).
MAC Address: 00:50:56:BB:C0:55 (VMware)
Nmap scan report for 10.0.11.22
Host is up (0.00085s latency).
MAC Address: 00:50:56:BB:C1:D4 (VMware)
Nmap scan report for 10.0.11.40
Host is up (-0.099s latency).
MAC Address: 00:50:56:BB:86:5E (VMware)
Nmap scan report for 10.0.11.60
Host is up (0.0013s latency).
MAC Address: 00:50:56:BB:C2:C2 (VMware)
Nmap scan report for 10.0.11.65
Host is up (0.00030s latency).
MAC Address: 00:50:56:BB:07:FC (VMware)
Nmap scan report for 10.0.11.68
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:64:75 (VMware)
Nmap scan report for 10.0.11.71
Host is up (-0.099s latency).
MAC Address: 00:50:56:BB:3E:12 (VMware)
Nmap scan report for 10.0.11.94
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:5D:E3 (VMware)
Nmap scan report for 10.0.11.95
Host is up (0.00042s latency).
MAC Address: 00:50:56:BB:89:A5 (VMware)
Nmap scan report for 10.0.11.98
Host is up (-0.092s latency).
MAC Address: 52:54:00:53:80:4D (QEMU Virtual NIC)
Nmap scan report for 10.0.11.123
Host is up (-0.099s latency).
MAC Address: 00:50:56:BB:CA:49 (VMware)
Nmap scan report for 10.0.11.124
Host is up (0.00038s latency).
MAC Address: 00:50:56:BB:67:75 (VMware)
Nmap scan report for 10.0.11.130
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:CD:76 (VMware)
Nmap scan report for 10.0.11.133
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:1F:64 (VMware)
Nmap scan report for 10.0.11.137
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:BA:51 (VMware)
Nmap scan report for 10.0.11.142
Host is up (0.00055s latency).
MAC Address: 00:50:56:BB:92:75 (VMware)
Nmap scan report for 10.0.11.143
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:58:0F (VMware)
Nmap scan report for 10.0.11.144
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:05:B4 (VMware)
Nmap scan report for 10.0.11.145
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:1A:4E (VMware)
Nmap scan report for 10.0.11.146
Host is up (-0.10s latency).
MAC Address: 52:54:00:53:80:4D (QEMU Virtual NIC)
Nmap scan report for 10.0.11.147
Host is up (0.00032s latency).
MAC Address: 00:50:56:BB:52:B1 (VMware)
Nmap scan report for 10.0.11.148
Host is up (-0.10s latency).
MAC Address: 00:50:56:BB:47:0E (VMware)
Nmap scan report for 10.0.11.150
Host is up (0.00037s latency).
MAC Address: 00:50:56:BB:E6:05 (VMware)
Nmap scan report for 10.0.11.151
Host is up (0.00048s latency).
MAC Address: 00:50:56:BB:E5:EA (VMware)
Nmap scan report for 10.0.11.153
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:1F:0C (VMware)
Nmap scan report for 10.0.11.171
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:3E:A2 (VMware)
Nmap scan report for 10.0.11.175
Host is up (-0.099s latency).
MAC Address: 00:50:56:BB:29:BA (VMware)
Nmap scan report for 10.0.11.176
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:A2:26 (VMware)
Nmap scan report for 10.0.11.181
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:69:32 (VMware)
Nmap scan report for 10.0.11.184
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:E6:4E (VMware)
Nmap scan report for 10.0.11.199
Host is up (-0.100s latency).
MAC Address: 00:50:56:BB:3D:1F (VMware)
Nmap scan report for 10.0.11.170
Host is up.
Nmap done: 256 IP addresses (34 hosts up) scanned in 5.08 seconds