Created
August 27, 2016 22:42
-
-
Save mgeeky/cd3092cf60fd513d786286a21c6fa915 to your computer and use it in GitHub Desktop.
Script converting nmap's greppable output (-oG) into a printable per-host tables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Simple script converting nmap's greppable output into a | |
# printable per-host table with protocol, port, state and service | |
# columns in it. | |
# | |
# | |
# WARNING: | |
# This script looks for gnmap (-oG) files within | |
# current working directory (cwd) | |
# | |
for host in $(find -name "*.gnmap" | sort -t'.' -n -k5) | |
do | |
if cat $host | grep -q "Status: Up" && cat $host | grep -q "Ports:"; then | |
hostip=$(grep Ports $host | cut -d' ' -f2) | |
ports=$(cat ${hostip}*.gnmap | grep Ports | cut -d: -f3 | sed 's:/, :\n:g' | awk '{$1=$1}1') | |
IFS=$'\n' | |
echo -e "\n\nHost: $hostip\n" | |
echo -e "Proto\t| Port\t| State\t\t| Service" | |
echo -e "----------------------------------------------------" | |
for port in $ports | |
do | |
proto=$(echo $port | cut -d/ -f3) | |
portnum=$(echo $port | cut -d/ -f1) | |
state=$(echo $port | cut -d/ -f2) | |
service=$(echo $port | cut -d/ -f5) | |
printf "%s\t| %-5s\t| %-13s\t| %s\n" $proto $portnum $state $service | |
done | sort -u -k3,3 -n | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment