Skip to content

How to calculate TCP connection infomation without ss and netstat

sort by remote port

array=($(tail -n +2 /proc/net/tcp | cut -d":" -f"4"|cut -d" " -f"1"))
for port in ${array[@]}; do echo $((0x$port)); done | sort | uniq -c

sort by local port

array=($(tail -n +2 /proc/net/tcp | cut -d":" -f"3"|cut -d" " -f"1"))
for port in ${array[@]}; do echo $((0x$port)); done | sort | uniq -c

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App