awknmap

Nmap output with IP and MAC address in same line


Given the answer to this question,

I would like to know how to obtain from the following output:

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

The following parse result ouput:

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

Thank you.


Solution

  • Following awk may help you in same.

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