Nmap输出,IP和MAC地址在同一行

时间:2018-01-16 16:45:41

标签: awk nmap

给出this question的答案,

我想知道如何从以下输出中获取:

Nmap scan report for 192.168.1.38
Host is up (0.0092s latency).
MAC Address: B8:78:2E:XX:XX:XX (Apple)
Nmap scan report for 192.168.1.39
Host is up (0.0092s latency).
MAC Address: 40:6C:8F:XX:XX:XX (Apple)
Nmap scan report for 192.168.1.201
Host is up (0.019s latency).
MAC Address: 3C:DF:A9:XX:XX:XX (Arris Group)
Nmap done: 256 IP addresses (3 hosts up) 

scanned in 1.77 seconds

以下解析结果输出:

192.168.1.38 B8:78:2E:XX:XX:XX
192.168.1.39 40:6C:8F:XX:XX:XX
192.168.1.201 3C:DF:A9:XX:XX:XX

谢谢。

4 个答案:

答案 0 :(得分:2)

关注awk可能对您有帮助。

awk '
/Nmap scan report/{
  val=$NF;
  next
}
/MAC Address:/{
  sub(/.*Address: /,"");
  sub(/ .*/,"");
  print val,$0
}
'   Input_file

答案 1 :(得分:0)

speed = 5; // no point in updating it on every iteration
for(auto & gui: allguis)
{
    if(gui.activated)
    {
        gui.position.x = gui.position.x + gui.distanceX * speed;
        gui.position.y = gui.position.y + gui.distanceY * speed;
    }
}  

输入:

$ awk '/Nmap scan/{ip=$NF;next}ip && /MAC/{print ip, $3}' infile
192.168.1.38 B8:78:2E:XX:XX:XX
192.168.1.39 40:6C:8F:XX:XX:XX
192.168.1.201 3C:DF:A9:XX:XX:XX

$ awk '/Nmap scan|MAC/{gsub(/\(.*/,"");printf "%s%s", $NF, ++c%2?OFS:RS}' infile
192.168.1.38 B8:78:2E:XX:XX:XX
192.168.1.39 40:6C:8F:XX:XX:XX
192.168.1.201 3C:DF:A9:XX:XX:XX

答案 2 :(得分:0)

贷记this post

sudo nmap -sP 172.31.201.0/24 | awk '/Nmap scan report for/{printf $5;}/MAC Address:/{print " => "$3;}' | sort

答案 3 :(得分:0)

添加到上面的帖子以获取包含 IP、MAC 和制造商的排序列表

sudo nmap -sP 192.168.1.0/24 | awk '/Nmap scan report for/{printf $5;}/MAC 地址:/{print " => "$3,$4,$5,$6,$7,$8;}' |排序