On Fri, 08 Jan 2016 06:22:41 +0000, Mark Cassidy wrote:
> Is there a way to get IP address geolocation from the command line
Nevermind.
I figured out a way to get IP address city and state from the linux CLI.
$ ls -l /usr/share/GeoIP/
$ sudo apt-get install geoip-bin
$ geoiplookup -v 100.9.53.236
$ geoiplookup 100.9.53.236
$ geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat 100.9.53.236
$ cd /tmp
$ wget
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
$ gunzip GeoIP.dat.gz
$ sudo cp GeoIP.dat /usr/share/GeoIP/
$ geoiplookup 100.9.53.236
$ wget
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
$ gunzip GeoLiteCity.dat.gz
$ sudo cp GeoLiteCity.dat /usr/share/GeoIP/
$ geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat 100.9.53.236
This output the country for a given list of IP addresses.
$ echo "100.9.53.236 104.208.39.105 104.53.124.192" > /tmp/list-of-ips.txt
$ output=/tmp/outputfile.csv; echo "ip,country" > $output; for i in $( cat /tmp/list-of-ips.txt ); do echo "$i,\"$( geoiplookup -f /usr/share/GeoIP/GeoIP.dat $i | cut -d' ' -f4-99 )\"" >> $output; done
This output the city for a given list of IP addresses..
$ echo "100.9.53.236 104.208.39.105 104.53.124.192" > /tmp/list-of-ips.txt
$ output=/tmp/outputfile.csv; echo "ip,country" > $output; for i in $( cat /tmp/list-of-ips.txt ); do echo "$i,\"$( geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat $i | cut -d' ' -f4-99 )\"" >> $output; done
I got the idea from here.
https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
https://pleasefeedthegeek.wordpress.com/2012/05/09/geolocation-lookups-in-linux-ubuntu/