Skip to content

Instantly share code, notes, and snippets.

@danielmiessler
Created July 19, 2014 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmiessler/16d016dfb01410f195de to your computer and use it in GitHub Desktop.
Save danielmiessler/16d016dfb01410f195de to your computer and use it in GitHub Desktop.
Get GeoLocation from a list of IP Addresses
#!/usr/bin/env bash
cat /var/log/apache2/ | awk '{print $1}' > ips.txt
uniq ips.txt > uniques.txt
IPS='cat uniques.txt'
echo "" > ./ipinfo.csv
for i in $IPS
do
echo "$i,'host $i | awk '{print $5}'','geoiplookup $i | cut -d "," -f2 | sed -e 's/^[ \t]*//'','geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $i | cut -d "," -f3 | sed -e 's/^[ \t]*//'','geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $i | cut -d "," -f4 | sed -e 's/^[ \t]*//''" >> ipinfo.csv
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment