Dada la respuesta a esta pregunta,

Me gustaría saber cómo obtener de la siguiente salida:

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

La siguiente salida de resultado de análisis:

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

Gracias.

0
EB- 16 ene. 2018 a las 19:45

3 respuestas

La mejor respuesta

Seguir awk puede ayudarte en lo mismo.

awk '
/Nmap scan report/{
  val=$NF;
  next
}
/MAC Address:/{
  sub(/.*Address: /,"");
  sub(/ .*/,"");
  print val,$0
}
'   Input_file
2
RavinderSingh13 16 ene. 2018 a las 16:52
$ 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

Entrada:

$ cat infile
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) 
1
Akshay Hegde 16 ene. 2018 a las 19:24

Créditos a esta publicación

sudo nmap -sP 172.31.201.0/24 | awk '/Nmap scan report for/{printf $5;}/MAC Address:/{print " => "$3;}' | sort
0
Pipo 15 feb. 2019 a las 19:41