Python Ip To Location Trace Function
To install the geoip2 module, type:
#pip install geoip2 //On Terminal
If you are not able to use pip, you may also use easy_install
from the source directory:
IP Geolocation Usage
IP geolocation is inherently imprecise. Locations are often near the center of the population. Any location provided by a GeoIP2 database or web service should not be used to identify a particular address or household.
To use this API, you first create either a web service object with your MaxMind account_id and license_key or a database reader object with the path to your database file. After doing this, you may call the method corresponding to request type (e.g., city or country), passing it the IP address you want to look up.
If the request succeeds, the method call will return a model class for the end point you called. This model in turn contains multiple record classes, each of which represents part of the data returned by the web service.
If the request fails, the client class throws an exception.
//Write Your Python Script
r = requests.get('https://get.geojs.io/')
ip_request = requests.get('https://get.geojs.io/v1/ip.json')
ipAdd = ip_request.json()['ip']
url = 'https://get.geojs.io/v1/ip/geo/'+ ipAdd +'.json'
geo_request = requests.get(url)
geo_data = geo_request.json()