首页 > Linux系统管理 > 用nmap 搜出1个网段的ip和mac地址对应关系
2015
09-14

用nmap 搜出1个网段的ip和mac地址对应关系

先用一个IP为例子,把mac和IP对应起来

# nmap  -sP -n 192.168.40.126
 
Starting Nmap 5.51 ( http://nmap.org ) at 2015-09-14 11:22 CST
Nmap scan report for 192.168.40.126
Host is up (0.00016s latency).
MAC Address: 74:D0:2B:34:99:23(Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

现在要把IP和MAC取出来

# nmap  -sP -n 192.168.40.126|awk '$2~/scan|Address/'|awk '{if($2~/Address/) print $3; else print $5}'
192.168.40.126
74:D0:2B:34:99:23

弄成一行

# nmap  -sP -n 192.168.40.126|awk '$2~/scan|Address/'|awk '{if($2~/Address/) print $3; else print $5}' |paste -d" " - -
192.168.40.126 74:D0:2B:34:99:23

这就是我最终要的结果,要取一个网段把ip改成192.168.40.* 就可以了

如果想再加些其它字段进去可以再加个awk

# nmap  -sP -n 192.168.40.126|awk '$2~/scan|Address/'|awk '{if($2~/Address/) print $3; else print $5}' |paste -d" " - -|awk '{print "ether-wake",$2,";","echo wakeup",$1}'
ether-wake 74:D0:2B:34:99:23 ; echo wakeup 192.168.40.126

 

最后编辑:
作者:saunix
大型互联网公司linux系统运维攻城狮,专门担当消防员

留下一个回复