Linux-Networking

如何找出網路上所有機器的mac地址

  • March 1, 2016

有沒有一些簡單的方法可以找出我網路上所有機器的 mac 地址,而不是對每台機器進行 SSH,ifconfig | grep HWaddr如果網路上有 300 台機器,我真的需要一些簡單的解決方案。

您可以使用nmap執行 ping 掃描。

nmap -sP 192.168.254.*

Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-09 11:32 GMT
Host xyzzy.lan (192.168.254.189) is up (0.00022s latency).
MAC Address: 00:0C:29:5B:A5:E0 (VMware)
Host plugh.lan (192.168.254.196) is up (0.00014s latency).
MAC Address: 00:0C:29:2E:78:F1 (VMware)
Host foo.lan (192.168.254.200) is up.
Host bar.lan (192.168.254.207) is up (0.00013s latency).
MAC Address: 00:0C:29:2D:94:A0 (VMware)
Nmap done: 256 IP addresses (4 hosts up) scanned in 3.41 seconds

編輯:

將輸出過濾到 IP -> MAC 的 sed 腳本 - 將其放入文件中。

/^Host.*latency.*/{
   $!N
   /MAC Address/{
       s/.*(\(.*\)) .*MAC Address: \(.*\) .*/\1 -> \2/
   }
}  
/[Nn]map/d
s/^Host .*is up/& but MAC Address cannot be found/

並像這樣使用它

nmap -sP 192.168.254.0/20 | sed -f sedscript
192.168.254.189 -> 00:0C:29:5B:A5:E0
192.168.254.196 -> 00:0C:29:2E:78:F1
Host foo.lan (192.168.254.200) is up but MAC Address cannot be found.
192.168.254.207 -> 00:0C:29:2D:94:A0

引用自:https://serverfault.com/questions/245136