Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BeFiveINFO/d600a17bb43b8f8267d0 to your computer and use it in GitHub Desktop.
Save BeFiveINFO/d600a17bb43b8f8267d0 to your computer and use it in GitHub Desktop.
#!/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