text - How to grep specific lines from nmap -O output? -
i got many files named 192.168.203.txt
output of
sudo nmap -o --top-ports 192.168.203.* >>192.168.203.txt
the output looks below:
nmap scan report 192.168.203.29 host (0.00067s latency). port state service 21/tcp closed ftp 22/tcp closed ssh 23/tcp closed telnet 25/tcp closed smtp 80/tcp open http 110/tcp closed pop3 139/tcp filtered netbios-ssn 443/tcp closed https 445/tcp filtered microsoft-ds 3389/tcp filtered ms-wbt-server device type: general purpose running: microsoft windows 2008|7 os cpe: cpe:/o:microsoft:windows_server_2008::sp2 cpe:/o:microsoft:windows_7 os details: microsoft windows server 2008 sp2, microsoft windows 7 or windows server 2008 sp1 network distance: 6 hops
i want grep ip 192.168.203.29
http
or ssh
or other ports open
sepetately. maybe pipe result ip
file named http_open_ip.txt
.
i have tried grep ftp
commands:
cat *.txt|grep -b 3 "ftp"|grep -b3 "open"|grep "192.168."|awk '{print $5}'|sort -t . -k 3,3n -k 4,4n> ftp_open_ip.txt
thus, got file ftp_open_ip.txt
. found command not work other keywords ssh
stmp
. should ?
i not clear want. perhaps, want in files , ip have http port open in 1 file, ssh port open in file. same ip may present in multiple files. assuming that, below awk
solution
awk 'begin{http_open="http_open";ssh_open="ssh_open";ftp_open="ftp_open"} /nmap scan report for/{ip=$5} /ftp/ && /open/{print "ftp open " ip >> ftp_open} /ssh/ && /open/{print "ssh open " ip >> ssh_open } /http/ && /open/{print "http open " ip >> http_open} ' <filename>
it assumes file containing data in same order shown in example. nmap scan report for
line has ip in 5th field. after that, rest simple. if ftp, ssh, http etc found along open
status, redirect output in corresponding file.
Comments
Post a Comment