A project to familiarize myself that I'm working on is to parse through an nmap
result.
(I know of the -oG
option, but I'm working with grep
, awk
, for
, and while
loops here).
Below is what I'm trying to parse through:
Starting Nmap 7.60 ( https://nmap.org ) at 2017-12-05 11:26 EST
Nmap scan report for house.router.nick (192.168.1.1)
Host is up (0.00059s latency).
Not shown: 995 closed ports
PORT STATE SERVICE
22/tcp open ssh
53/tcp open domain
427/tcp open svrloc
1900/tcp open upnp
MAC Address: 50:C7:BF:A8:CF:C8 (Tp-link Technologies)
Nmap scan report for 192.168.1.2
Host is up (0.00034s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
139/tcp open netbios-ssn
445/tcp open microsoft-ds
MAC Address: 48:F8:B3:C9:AE:BB (Cisco-Linksys)
What I want to get is this:
22/ssh
====
192.168.1.1
192.168.1.2
http
===
192.168.1.2
So far, I have this:
grep -E "tcp.*open" nmap.txt | awk '{ print $3 }' | sort | uniq
For the life of me, I can't figure out how to get this into a loop of sorts and get the desired output from above.
Can you please help me learn and explain why you came to the solution you did? No point in getting a potential solution if I can't understand the logic behind it.