https://www.ostechnix.com/find-geolocation-ip-address-commandline
A while ago, we wrote an article that described how to find out your geolocation from commandline using whereami
utility. Today, we will see how to find the geolocation of an IP
address. Of course, you can see this details from a web browser. But, it
is lot easier to find it from commandline. geoiplookup
is a command line utility that can be used to find the Country that an
IP address or hostname originates from. It uses the GeoIP library and
database to collect the details of an IP address.
This brief guide describes how to install and use geoiplookup utility
to find the location of an IP address in Unix-like operating systems.
To install it on Arch Linux and its derivatives, run:
Go to geoip default database folder:
Cheers!
Find The Geolocation Of An IP Address Using Geoiplookup From Commandline
Install Geoiplookup
Geoiplookup is available in the default repositories of most Linux operating systems.To install it on Arch Linux and its derivatives, run:
sudo pacman -S geoipOn Debian, Ubuntu, Linux Mint:
sudo apt-get install geoip-binOn RHEL, CentOS, Fedora, Scientific Linux:
sudo yum install geoipOn SUSE/openSUSE:
sudo zypper install geoip
Usage
Once installed, you can find out any IP address’s geolocation like below.geoiplookup 80.60.233.195The above command will find and display the Country that 80.60.233.195 originates from, in the following format:
GeoIP Country Edition: NL, Netherlands
Download – Free eBook: “Computer Networking Concepts”
Download and update Geoip databases
Generally, the default location of Geoip databases is /usr/share/GeoIP/. The databases might be bit outdated. You can download the latest databases that contains the updated geolocation details, from Maxmind. It is the website that offers the geolocation of an IP address.Go to geoip default database folder:
cd /usr/share/GeoIP/Download the latest databases:
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gzNow, run the geoiplookup command to find most up-to-date geolocation details of an IP address.
geoiplookup 216.58.197.78Sample output:
GeoIP Country Edition: US, United StatesAs you see in the above output, it displays only the country location. Geoiplookup can even display more details such as the state, city, zip code, latitude and longitude etc. To do so, you need to download the city databases from Maxmind like below. Make sure you’re downloading it in /user/share/GeoIP/ location.
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gzNow, run the below command to get more details of an IP address’s geolocation.
geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat 216.58.197.78Sample output would be:
GeoIP City Edition, Rev 1: US, CA, California, Mountain View, 94043, 37.419201, -122.057404, 807, 650If you have saved the database files in a custom location other than the default location, you can use ‘-d’ parameter to specify the path. Say for example, if you have saved the database files in /home/sk/geoip/, the command to find the geolocation of an IP address would be:
geoiplookup -d /home/sk/geoip/ 216.58.197.78For more details, see man pages.
man geoiplookupHope this helps. if you find this guide useful, please share it on your social networks and support us.
Cheers!
No comments:
Post a Comment