Skip to content

Instantly share code, notes, and snippets.

@marcostolosa
Forked from anibalardid/extractPorts.sh
Created May 6, 2023 17:50
Show Gist options
  • Save marcostolosa/fb0cd6fb1649de1d05946dcaeb4e15b4 to your computer and use it in GitHub Desktop.
Save marcostolosa/fb0cd6fb1649de1d05946dcaeb4e15b4 to your computer and use it in GitHub Desktop.
Extract ports from nmap output #hack #security #s4vitar
# Used:
# nmap -p- --open -T5 -v -n ip -oG allPorts
# Extract nmap information
# Run as:
# extractPorts allPorts
function extractPorts(){
ports="$(cat $1 | grep -oP '\d{1,5}/open' | awk '{print $1}' FS='/' | xargs | tr ' ' ',')"
ip_address="$(cat $1 | grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' | sort -u | head -n 1)"
echo -e "\n[*] Extracting information...\n" > extractPorts.tmp
echo -e "\t[*] IP Address: $ip_address" >> extractPorts.tmp
echo -e "\t[*] Open ports: $ports\n" >> extractPorts.tmp
echo $ports | tr -d '\n' | xclip -sel clip
echo -e "[*] Ports copied to clipboard\n" >> extractPorts.tmp
cat extractPorts.tmp; rm extractPorts.tmp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment