Last active
June 10, 2022 12:43
-
-
Save aerostitch/50de732f88ca7aeb9bb8 to your computer and use it in GitHub Desktop.
Sorting the connections to a linux server by its status and bu combination of source/destination IP and port
This file contains hidden or 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
# By status | |
netstat -an | awk '$6 ~ /^[A-Z_]+[1-2]*$/{a[$6]++} END {for (i in a) print a[i], "\t", i}' | sort -n | |
# By source IP:port | |
netstat -an | awk '$4 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$/{a[$4]++} END {for (i in a) print a[i], "\t", i}' | sort -n | |
# By destination IP:port | |
netstat -an | awk '$5 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$/{a[$5]++} END {for (i in a) print a[i], "\t", i}' | sort -n | |
# Just by destination IP | |
netstat -an | awk '$5 ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$/{a[gensub(/^(.+):.+$/, "\\1", "g", $5)]++} END {for (i in a) print a[i], "\t", i}' | sort -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment