0

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?

Floyd Ball
  • 11
  • 2

1 Answers1

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