Skip to content

Instantly share code, notes, and snippets.

@umutbasal
Last active January 30, 2025 16:21
Show Gist options
  • Save umutbasal/b1910c6d2b3abad42ef7fc1be6362801 to your computer and use it in GitHub Desktop.
Save umutbasal/b1910c6d2b3abad42ef7fc1be6362801 to your computer and use it in GitHub Desktop.
Get top n TCP/UDP ports
ports(){
protocol=${1:-tcp}
count=${2:-65535}
curl -s https://svn.nmap.org/nmap/nmap-services | awk '!/^#/ && NF >= 3 && /'$protocol'/ {split($2, p, "/"); print p[1], $3}' | sort -k2,2nr | awk '{print $1}' | head -n $count | tr '\n' ',' | sed 's/,$//'
}
# Usage
# ports tcp 10 > ports.txt && naabu -ports-file=ports.txt -host 127.0.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment