有什么简单的方法可以找出网络上所有计算机的mac地址,而不是对每台ifconfig | grep HWaddr
计算机都进行SSH,如果网络上有300台计算机,我真的需要一些简单的解决方案。
有什么简单的方法可以找出网络上所有计算机的mac地址,而不是对每台ifconfig | grep HWaddr
计算机都进行SSH,如果网络上有300台计算机,我真的需要一些简单的解决方案。
Answers:
您可以使用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
编辑:
sed脚本将输出过滤到IP-> MAC-将其放入文件中。
/^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
使用nmap。以root身份运行它很重要,这样您可以获得MAC地址。例:
sudo nmap -sP 192.168.1.0/24
将扫描192.168.1.1-192.168.1.255。如果您不熟悉此子网表示法,请在Wiki上查找CIDR表示法。
您应该能够从任何最新的Linux发行版的存储库中获取nmap,例如
sudo apt-get install nmap
要么
sudo yum install nmap
我的网络的示例输出:
Host 192.168.1.1 is up (0.0069s latency).
MAC Address: 00:0D:54:9B:D8:F4 (3Com)
Host 192.168.1.78 is up (0.0068s latency).
MAC Address: 00:0C:29:BC:3D:1C (VMware)
Host 192.168.1.91 is up (0.0038s latency).
MAC Address: 00:0C:29:8A:F4:A3 (VMware)
Host 192.168.1.92 is up (0.0039s latency).
MAC Address: 00:0C:29:65:60:5F (VMware)
Host 192.168.1.158 is up (0.033s latency).
MAC Address: 00:0C:29:82:24:EA (VMware)
Host 192.168.1.186 is up (0.0024s latency).
MAC Address: 00:0C:29:3E:26:1F (VMware)
Host 192.168.1.190 is up (0.0066s latency).
只要您从同一网段中的主机运行此命令,nmap
就会报告发现每个主机的所有MAC地址。
例如:
sudo nmap 192.168.1.0/24 -sP
Starting Nmap 4.76 ( http://nmap.org ) at 2011-03-09 06:29 EST
Host old.net (192.168.1.1) appears to be up.
MAC Address: 00:18:39:C5:A1:DC (Cisco-Linksys)
对于MAC地址,我需要在Ubuntu机器上是root用户。同样,对于单个主机,一种简单的方法是仅对它进行ping操作并查看arp表,arp -a
如果您只想使用发行版的初始安装中通常包含的命令:
arp -a | grep -v incomplete
foo.net (192.168.1.145) at 00:0d:4b:6a:2c:cb [ether] on eth0
也许arp-scan也可以选择:
在此处查看示例: Arp-scan用户指南