Skip to content

Instantly share code, notes, and snippets.

@sven-hash
Last active May 30, 2022 16:13
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 sven-hash/56e1deb467b9ddb92b128a6772101cb7 to your computer and use it in GitHub Desktop.
Save sven-hash/56e1deb467b9ddb92b128a6772101cb7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# INSTALL wget https://gist.githubusercontent.com/sven-hash/56e1deb467b9ddb92b128a6772101cb7/raw -O /usr/local/bin/sockets && chmod +x /usr/local/bin/sockets
# RUN sockets <number of lines>, example sockets 15
RED="\e[31m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"
PORTS=(1080 1789 1790 8000 9000)
TOP=10
if [ ! -z ${TOP} ];then
TOP=$1
fi
for port in ${PORTS[@]};do
echo -e "${GREEN}Number of socket open for port $port${ENDCOLOR}"
ss -tan | grep $port | awk '{print $5}' | rev | cut -d: -f2- |rev | sort|uniq -c|sort -k3 | tail -${TOP}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment