Skip to content

Instantly share code, notes, and snippets.

@shamil
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamil/84bb07d55f3a20b4e2dc to your computer and use it in GitHub Desktop.
Save shamil/84bb07d55f3a20b4e2dc to your computer and use it in GitHub Desktop.
Some commands to find out listening ports
# find all listening ports
cat /proc/net/tcp | awk '$4 == "0A" {print $2}' | awk -F: '{print strtonum("0x"$2)}'
# find all listening ports and print their inodes as well
cat /proc/net/tcp | awk '$4 == "0A" {print $10" "$2}' | tr : ' ' | awk '{printf "%d %d\n", strtonum("0x"$3), $1}'
# find all socket for PID and print their inodes
find -L /proc/<PID>/fd -type s -printf "%i\n"
# find listening ports for by PID
ss -ltnp4 | grep 26532 | tr -dc '0-9 \n'
# find all Listening ports and their PID by proccess name
ss -ltnp4 | grep memcached | tr , ' ' | tr -dc '0-9 \n' | awk '{print $3" "$4}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment