Hello world!
Today I’m sharing with you a bash one-liner I made to more easily read through nmap scan results with the grepable format within your terminal (-oG option or -oA .gnmap file).
Its intended purpose is to display only useful information with indents and colour 😊
Here is how it looks on my kali machine:
And with a quick live demo:
The hosts’ status and the filtered ports are striped from the output to only display ‘interesting’ results. This behavior can be useful when you’re going through big network scans and/or when your scan has more than one -’v’ option and reports all ports states.
I’ve made it as a bash function so you can directly paste it in your .bashrc file and simply use it as an alias-like command and give the file(s) you want to read as parameter.
Here it goes:
nmapless() { grep -hv "Status: Down\|Status: Up" $@ |grep "^#\|/open/" |sed s/'\t'/'\n\t'/g |sed s/'\/, '/'\n\t\t'/g |sed s/'Ports: '/'Ports:\n\t\t'/g |grep -v "/closed/\|filtered/" |sed "/Host:/ s=(\(.*\))=($(tput setaf 4)\1$(tput sgr0))=" |sed "s/Host:/$(tput setaf 1)&$(tput sgr0)/g" |sed "/\t\t/ s=\(\t\t[0-9]*\)=$(tput setaf 2)\1$(tput sgr0)=" |awk -F '/' '{OFS=FS; if (NF<2) {print;next} else $7="\033[01;33m"$7"\033[00m";print}' |sed "/OS:/ s= .*=$(tput setaf 5)&$(tput sgr0)=" |sed "s/^#.*/$(tput setaf 6)&$(tput sgr0)/" |less -r;}nmapcat() { grep -hv "Status: Down\|Status: Up" $@ |grep "^#\|/open/" |sed s/'\t'/'\n\t'/g |sed s/'\/, '/'\n\t\t'/g |sed s/'Ports: '/'Ports:\n\t\t'/g |grep -v "/closed/\|filtered/" |sed "/Host:/ s=(\(.*\))=($(tput setaf 4)\1$(tput sgr0))=" |sed "s/Host:/$(tput setaf 1)&$(tput sgr0)/g" |sed "/\t\t/ s=\(\t\t[0-9]*\)=$(tput setaf 2)\1$(tput sgr0)=" |awk -F '/' '{OFS=FS; if (NF<2) {print;next} else $7="\033[01;33m"$7"\033[00m";print}' |sed "/OS:/ s= .*=$(tput setaf 5)&$(tput sgr0)=" |sed "s/^#.*/$(tput setaf 6)&$(tput sgr0)/";}
I also made a commented version of each piped command here:
You can naturally tune it to your needs and wishes: display hosts status, display filtered and closed ports, change colours, etc.
Feedback is welcome 😀 I hope you’ll like it !