Created
December 10, 2016 11:21
-
-
Save johan-bjareholt/2ca77a0a27c40ccab81fc8522d4e3591 to your computer and use it in GitHub Desktop.
findlocs.sh
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 | |
# 1. ss | |
# 2. Remove header | |
# 3. Only print ip | |
# 4. RegEx away port number | |
IPS=$(ss --tcp | tail -n +2 | awk '{ print $5 }' | sed -e 's/\(.*\):.*/\1/g') | |
COUNTRIES="" | |
for IP in $IPS; do | |
# 1. Geoiplookup | |
# 2. filter invalid ips and ips that cannot be found | |
# 3. Select only country code | |
# 4. Remove comma in country code | |
COUNTRY=$(geoiplookup $IP | grep -vwE '(can|not)' | awk '{print $4}' | tr ',' ' ') | |
COUNTRIES="$COUNTRIES $COUNTRY" | |
done | |
echo $COUNTRIES | tr ' ' '\n' | sort | uniq -c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment