Created
February 8, 2016 19:58
-
-
Save BeFiveINFO/d600a17bb43b8f8267d0 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# requires geoiplookup, do "brew install geoip" | |
# and brew install geoiplookup | |
# this is how to extract ip addresses and the count of occurances | |
# egrep -o '[0-9]+(\.[0-9]+){3}' < accesslog.txt | sort | uniq -c | sort -nr > access.txt | |
# specify the output access.txt as an argument, | |
if [ $# -ne 1 ]; then | |
echo "$# argument specified" 1>&2 | |
echo "this script requires 1 argument" 1>&2 | |
exit 1 | |
fi | |
numLine=1 | |
cat $1 | while read line | |
do | |
ipaddress=`echo ${line} | grep -Eo "[0-9]+(\.[0-9]+){3}"` | |
geoipdata=`geoiplookup ${ipaddress} | cut -f2 -d ','| sed -e 's/^[ \t]*//'` | |
echo \#$numLine: $line $geoipdata | |
numLine=$((numLine + 1)) | |
done | |
#memo | |
# select any lines with a specific domain | |
# ^(?!.*http://(subdomain1|subdomain2).domain.com/).+$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment