Skip to content

Instantly share code, notes, and snippets.

@cxzero
Last active June 13, 2022 16:00
Show Gist options
  • Save cxzero/492ff5afd9da485a77a45e7bd1c7b8ce to your computer and use it in GitHub Desktop.
Save cxzero/492ff5afd9da485a77a45e7bd1c7b8ce to your computer and use it in GitHub Desktop.
Utility to extract ports from nmap grepable output
#!/bin/bash
# To be used with nmap grepable output (-oG option)
if [ -z $1 ]; then
echo "Usage: $(basename $0) <grepable-nmap-input-file>"
exit -1
fi
ports="`cat $1 | grep -oP '\s\K[0-9]+(?=/)'`"
echo $ports | xargs | sed 's/ /,/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment