Skip to content

Instantly share code, notes, and snippets.

@dejurin
Last active August 11, 2021 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dejurin/ba63099800d0c202f9d12a913bd3c29d to your computer and use it in GitHub Desktop.
Save dejurin/ba63099800d0c202f9d12a913bd3c29d to your computer and use it in GitHub Desktop.
IP Geolocation API - Python requests
# https://api.ipgeolocation.io/ipgeo?apiKey=API_KEY&ip=8.8.8.8
# https://ipgeolocation.io/documentation/ip-geolocation-api.html
import requests
class IPGeoLocation:
url = 'https://api.ipgeolocation.io/ipgeo'
def __init__(self, apiKey):
self.apiKey = apiKey
def getInfo(self, ip: str = None):
try:
r = requests.get(
url=self.url,
params={
'apiKey': self.apiKey,
'ip': ip,
}
)
except requests.exceptions.ConnectionError as err:
return False
except requests.exceptions.HTTPError as err:
return False
data = r.json()
if 'ip' in data:
return data
"""""
if __name__ == "__main__":
x = IPGeoLocation(apiKey='')
print(x.getInfo('8.8.8.8'))
"""""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment