-
Notifications
You must be signed in to change notification settings - Fork 3
Setup Lookup Service
Mingwei Zhang edited this page Dec 16, 2019
·
3 revisions
Install the python package first:
Install and start service:
sudo cp ipmeta.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable ipmeta
sudo systemctl start ipmeta
Python util code:
import logging
import requests
def get_location(ip):
"""get location of the IP address, returning latitude,longitude pair"""
location = []
country_code = ""
try:
response = requests.get("http://ipmeta.limbo.caida.org/iplookup/" + ip).json()
if len(response) == 1:
if "lat_long" in response[0]:
location = response[0]["lat_long"]
if "country_code" in response[0]:
country_code = response[0]["country_code"]
except Exception as e:
logging.error("retrieving location for {} failed: {}".format(ip, e.message))
finally:
return location, country_code
if __name__ == '__main__':
print(get_location("8.8.8.8"))