Created
August 4, 2014 05:21
-
-
Save meoow/ef197d10d8b072077638 to your computer and use it in GitHub Desktop.
Show current listening ports and established connections of system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $1 =~ (tcp|udp) ]] || [ -z "$1" ];then | |
pass | |
else | |
echo Wrong option! | |
exit 1 | |
fi | |
trap 'tput clear;exit 0' 2 | |
col=$(tput cols) | |
while true; do | |
tput clear | |
lsof -nPi4$1 |awk 'NR>1{split($9,ip,"->") | |
split(ip[1],ip1,":") | |
split(ip[2],ip2,":") | |
printf("%-10s%5s %-15s%1s%5s %1s %-15s%1s%5s %s\n",$1,$2,ip1[1],(NR>1?":":""),ip1[2],ip[2]!=""?">":"",ip2[1],length(ip2)>1?":":"",ip2[2],$10) | |
}' | |
tput cup 0 $col | |
sleep 3 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment