(self, ip, dns=True)
return ipinfo
Return information on an IP address
        {"asn", "asn_name", "city", "country"}
Return information on an IP address
        {"asn", "asn_name", "city", "country"}
Return information on an IP address { asn asn_name city country }
def ipinfo(self, ip, dns=True):
        """
        Return information on an IP address
        {"asn", "asn_name", "city", "country"}
        """
        self.check_geoipdb()
        ipinfo = {}
        if dns:
            ipinfo["hostname"] = ""
            try:
                ipinfo["hostname"] = socket.gethostbyaddr(ip)[0]
            except socket.herror:
                pass
        try:
            citydb = geoip2.database.Reader(self.geocity)
            res = citydb.city(ip)
            ipinfo["city"] = res.city.name
            ipinfo["country"] = res.country.name
        except geoip2.errors.AddressNotFoundError:
            ipinfo["city"] = "Unknown"
            ipinfo["country"] = "Unknown"
        except FileNotFoundError:
            print(
                "GeoIP database not found, make sure you have correctly installed geoipupdate"
            )
            sys.exit(1)

        asninfo = self.ip_get_asn(ip)
        ipinfo["asn"] = asninfo["asn"]
        ipinfo["asn_name"] = asninfo["name"]
        ipinfo["specific"] = ""
        try:
            with open(self.specific_ips) as f:
                data = f.read().split("\n")
            for d in data:
                if d.strip().startswith(ip):
                    ipinfo["specific"] = d.split(",")[1].strip()
        except FileNotFoundError:
            pass
            # TODO: add private
        asnc = CommandAsn()
        res = asnc.asn_caida(ipinfo["asn"])
        ipinfo["asn_type"] = res["type"]
        return ipinfo
def ipinfo ( self , ip , dns = True ) : self . check_geoipdb ( ) ipinfo = { } if dns : ipinfo [ "hostname" ] = "" try : ipinfo [ "hostname" ] = socket . gethostbyaddr ( ip ) [ 0 ] except socket . herror : pass try : citydb = geoip2 . database . Reader ( self . geocity ) res = citydb . city ( ip ) ipinfo [ "city" ] = res . city . name ipinfo [ "country" ] = res . country . name except geoip2 . errors . AddressNotFoundError : ipinfo [ "city" ] = "Unknown" ipinfo [ "country" ] = "Unknown" except FileNotFoundError : print ( "GeoIP database not found, make sure you have correctly installed geoipupdate" ) sys . exit ( 1 ) asninfo = self . ip_get_asn ( ip ) ipinfo [ "asn" ] = asninfo [ "asn" ] ipinfo [ "asn_name" ] = asninfo [ "name" ] ipinfo [ "specific" ] = "" try : with open ( self . specific_ips ) as f : data = f . read ( ) . split ( "\n" ) for d in data : if d . strip ( ) . startswith ( ip ) : ipinfo [ "specific" ] = d . split ( "," ) [ 1 ] . strip ( ) except FileNotFoundError : pass # TODO: add private asnc = CommandAsn ( ) res = asnc . asn_caida ( ipinfo [ "asn" ] ) ipinfo [ "asn_type" ] = res [ "type" ] return ipinfo