Skip to content

Instantly share code, notes, and snippets.

@crackjack crackjack/

Created Apr 3, 2013
What would you like to do?
Bash Script to find Geolocation from IP Addresses in apache's access log. You need to have "geoiplookup" package from GeoLite package. The excerpts are taken from
#!/usr/bin/env bash
cat /var/log/apache2/access_log | awk '{print $1}' > ips.txt
uniq ips.txt > uniqips.txt
IPS=`cat uniqips.txt`
for i in $IPS
echo "$i,`geoiplookup $i | cut -d "," -f2 | sed -e 's/^[\t]//'`" >> ipinfo.csv

This comment has been minimized.

Copy link

REDLINK commented Dec 16, 2014

Shouldn't it be sort ips.txt | uniq > uniqips.txt?


This comment has been minimized.

Copy link

denics commented Nov 10, 2015

To get this output:, yy.yyy change the echo line with the following

echo "$i, `geoiplookup $i | awk -F, 'NR==2{print $7, $8}' | sed -e 's/,//'`" >> ipinfo.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.