Skip to content

Instantly share code, notes, and snippets.

@hqmatics
Created July 14, 2013 19:52
Show Gist options
  • Save hqmatics/5995636 to your computer and use it in GitHub Desktop.
Save hqmatics/5995636 to your computer and use it in GitHub Desktop.
netstat functions
# List connections for port
netstat -an | grep 12345
# List the number and type of active network connections
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
# Number of connections for each hosts
netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }'
# Number of connections for each port
netstat -tuna | awk -F':+| +' 'NR>2{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment