Beispiel #1
0
def lookup(ip_addr):
    url = f"http://www.geoplugin.net/json.gp?ip={ip_addr}"
    try:
        response = requests.get(url)
        if response.status_code != 200:
            logging.error("%s replyed with a not ok status code", url)
            return ""

        new_ip = IP()
        new_ip.insert_raw(response.json())
        new_ip.save()
        return new_ip
    except ConnectionError:
        logging.error("failed to fetch api details for %s", url)
        return ""
Beispiel #2
0
 def test_insert(self):
     new_ip = IP()
     new_ip.insert_raw(APIRESPONSE)
     new_ip.save()