Skip to content

Instantly share code, notes, and snippets.

@DanijelMi
Last active March 23, 2020 13:41
Show Gist options
  • Save DanijelMi/d019b5aff111908e5f3177c10857228b to your computer and use it in GitHub Desktop.
Save DanijelMi/d019b5aff111908e5f3177c10857228b to your computer and use it in GitHub Desktop.
Pipe in nmap stdout, output CSV format of ports suitable for Nessus. Install for bash: curl https://gist.githubusercontent.com/DanijelMi/d019b5aff111908e5f3177c10857228b/raw/347f5e41b7ce03567ac6245e1dee92214ab86dff/nmap2csv >> ~/.bashrc && source ~/.bashrc
# Usage: nmap {OPTIONS} {TARGET_IP} | nmap2csv
nmap2csv (){
# License: GPLv2
# Author: Danijel M.
# Brief help prompt
if [[ $1 == "-h" || $1 == "--help" ]]; then
printf "\e[32;1m Usage: nmap {OPTIONS} {TARGET_IP} | nmap2csv\e[0m \n"
return 0
fi
# Check for dependencies
DEPENDENCIES=(nmap grep sed printf cat)
for i in "${DEPENDENCIES[@]}"; do
which $i &> /dev/null && continue
printf "$i was not found on your system. Aborting.\n"
return 1
done
# 0:Get STDIN 1:Greedy find numbers 2: Newline into Comma+Space 3: remove tail Comma+Space
cat /dev/stdin | \
grep -oE '^[0-9]*' | \
sed -z 's/\n/, /g' | \
sed 's/..$/\n/'
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment