There is a module and lost file called GeoIP.dat. Usually Linux operating systems have this file pre-installed. In my case, Kali hasn’t it pre-installed so i will tell you how to get this file and how to work with IPs offline.
Download The IP Database
Depending what you want to do you can download the database from here : https://www.miyuru.lk/geoiplegacy
I choosed ipv4 db-ip-city.
sudo mkdir /usr/share/GeoIP/
sudo wget -N https://dl.miyuru.lk/geoip/dbip/city/dbip4.dat.gz -O /usr/share/GeoIP/GeoLite.dat.gz
sudo gunzip /usr/share/GeoIP/GeoLite.dat.gz
Install Python Module
pip3 install pygeoip
Working with geoip
python3 # To start python3
import pygeoip
g = pygeoip.GeoIP(“/usr/share/GeoIP/GeoLite.dat”)
g.country_name_by_addr(“205.185.223.142”)
You can use different methods to get information about an IP address.
Here are all methods :
g ist our variable, loaded with all IPs. The dot after the g is calling a function.
Region Lookup
g.region_by_addr(“205.185.223.142”)
g.region_by_name(“google.com”)
City Lookup
g.record_by_addr(“205.185.223.142”)
Organization Lookup
g.org_by_name(“dell.com”)
Timezone Lookup
g.time_zone_by_addr(“205.185.223.142”)
g.time_zone_by_name(“dell.com”)
ISP Lookup
g.isp_by_name(“dell.com”)
ASN Lookup
g.asn_by_name(“dell.com”)
Please note that if you get an error like : pygeoip.GeoIPError, then please another geoip.dat from their website.