Skip to content

Instantly share code, notes, and snippets.

@scmanjarrez
Last active March 28, 2024 16:26
Show Gist options
  • Save scmanjarrez/9d6c2995c0ec4bcbd7dbaa5b3d369611 to your computer and use it in GitHub Desktop.
Save scmanjarrez/9d6c2995c0ec4bcbd7dbaa5b3d369611 to your computer and use it in GitHub Desktop.
Small script to generate a list of ports to be scanned from the port detected by nmap
#!/bin/bash
declare -a tcp=()
declare -a udp=()
while IFS= read -r line; do
port=$(echo $line | awk '{print $4}')
[[ "$port" =~ "tcp" ]] && tcp+=("${port%%/*}") || udp+=("${port%%/*}")
done < "${1:-/dev/stdin}"
IFS=,
echo -n "-sS -p "
echo "${tcp[*]}"
echo -n "-sU -p "
echo "${udp[*]}"
# Usage:
# ❯ bash nmapparser.sh
# Discovered open port 445/tcp on 10.129.202.41
# Discovered open port 135/udp on 10.129.202.41
# Discovered open port 3389/tcp on 10.129.202.41
# Discovered open port 139/udp on 10.129.202.41
# Discovered open port 111/tcp on 10.129.202.41
# <Ctrl+D>
# -sS -p 445,3389,111
# -sU -p 135,139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment