Is there a specific module to python that can be imported to do IP location lookup from within python rather than having to navigate to a site?
Asked
Active
Viewed 213 times
0
-
tried to google ? what about `geoip` ? – Jithin Scaria Apr 11 '18 at 09:16
-
Possible duplicate of [Finding local IP addresses using Python's stdlib](https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib) – the.salman.a Apr 11 '18 at 09:19
1 Answers
2
There is no standard module to do this. However I would suggest using an online API to do this, you'll just need to make a HTTP request to it and parse the response most likely JSON.
ipinfo.io seems like a good service and is free for some scale projects. There documentation explains how to use it in python in detail too.
import requests
print requests.get('http://ipinfo.io/8.8.8.8').json()
Output:
{ "ip": "8.8.8.8", "hostname": "google-public-dns-a.google.com", "loc": "37.385999999999996,-122.0838", "org": "AS15169 Google Inc.", "city": "Mountain View", "region": "California", "country": "US", "phone": 650 }
For more info: https://ipinfo.io/developers

Tom Dee
- 2,516
- 4
- 17
- 25