Skip to content

Instantly share code, notes, and snippets.

@pwielgolaski
Last active January 26, 2017 20:41
Show Gist options
  • Save pwielgolaski/cd655afa50d9688ccecffa08730b22cd to your computer and use it in GitHub Desktop.
Save pwielgolaski/cd655afa50d9688ccecffa08730b22cd to your computer and use it in GitHub Desktop.
connection start per pid
netstat -tap --numeric-port 2>/dev/null |\
awk 'NR >2 { print $6,$4,$5,substr($7,0,index($7, "/")-1);}' |\
sort -ru |\
awk -v pids="$1" 'BEGIN {OFS=","} { port=substr($2,index($2,":")+1) } pids !~ $4 {next} /LISTEN/ { listen[port]=1; $1="LIS"; print $0; next} { (port in listen)?$1="IN":$1="OUT"; print $0 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment