Last active
October 5, 2020 12:31
-
-
Save theratman/51b7dc6a16f621f20cac748c3d6e4e7c to your computer and use it in GitHub Desktop.
Show top established IP connections to the ports 80(http) and 443 (https). This scripts use netstat (net-tools package) and geoiplookup to show IPs and the geographic location of each IP.
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 | |
while true; do | |
clear | |
if [ $# -gt 0 ]; then | |
echo "All State: CLOSE_WAIT CLOSING ESTABLISHED FIN_WAIT1 FIN_WAIT2 LAST_ACK LISTEN SYN_RECV TIME_WAIT etc" | |
netstat -ant | awk '! /LISTEN $/ {split($4, a, ":", seps); if (a[2] == "80" || a[2] == "443") {m=split($5, b, ":", seps); print b[m-1]} }' | sort | uniq -c | sort -n | tail -20 | awk '{printf("%s -> ", $0); system("geoiplookup " $0 " | cut -d\\ -f4-")}' | |
else | |
echo "Only State: ESTABLISHED" | |
netstat -ant | awk '/ESTABLISHED$/ {split($4, a, ":", seps); if (a[2] == "80" || a[2] == "443") {m=split($5, b, ":", seps); print b[m-1]} }' | sort | uniq -c | sort -n | tail -20 | awk '{printf("%s -> ", $0); system("geoiplookup " $0 " | cut -d\\ -f4-")}' | |
fi | |
sleep 3 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment