Skip to content

Instantly share code, notes, and snippets.

@openrijal
Created April 3, 2013 18:33
Show Gist options
  • Save openrijal/5303869 to your computer and use it in GitHub Desktop.
Save openrijal/5303869 to your computer and use it in GitHub Desktop.
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 http://danielmiessler.com/blog/a-simple-script-for-harvesting-dns-country-state-and-city-information-from-a-list-of-ip-addresses
#!/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
do
echo "$i,`geoiplookup $i | cut -d "," -f2 | sed -e 's/^[\t]//'`" >> ipinfo.csv
done
@denics
Copy link

denics commented Nov 10, 2015

To get this output: xxx.xxx.xxx.xxx, xx.xxx 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