示例#1
0
def test_ip_details():
    ii = IpInfo()
    deets = ii.ip_details("8.8.8.8")
    assert deets["ip"] == "8.8.8.8"
    assert deets["input_type"] == "ip"
    assert deets["reverse_dns"] == "dns.google"
    assert deets["maxmind_asn_name"] == "Google LLC"
    assert deets["maxmind_country_code"] == "US"
    assert deets["maxmind_country_name"] == "United States"
示例#2
0
    def resolve(self, ip_str, auto_load=True, resolve_host_name=False):
        if not self.loaded:
            if auto_load:
                self.load_memory()
            else:
                print "WARNING : Ip data should be loaded before calling resolve"
            if not self.loaded:
                return None
        ip = Utilx.ip2inet(ip_str)
        query = """
         SELECT c.iso_code_2, c.country FROM
         ip2nationCountries c,
         ip2nation i
	        WHERE
	            i.ip < {0}
	            AND
	            c.code = i.country
	        ORDER BY
	            i.ip DESC
	        LIMIT 0,1;""".format(ip)

        c = self.conn.cursor()
        c.execute(query)
        res = c.fetchone()

        country_code = "" if res is None or len(res) == 0 else res[0]
        country = "" if res is None or len(res) == 0 else res[1]
        host_name = ""

        if resolve_host_name:
            host_name = Utilx.get_host(ip_str)

        info = IpInfo(country_code, country, host_name)
        return info
示例#3
0
def test_ip_details_list():
    ii = IpInfo()
    testlist = ["8.8.8.8", "1.1.1.1"]

    deetlist = ii.ip_details_list(testlist)
    assert len(deetlist) == 2

    assert deetlist[0]["ip"] == "8.8.8.8"
    assert deetlist[0]["input_type"] == "ip"
    assert deetlist[0]["reverse_dns"] == "dns.google"
    assert deetlist[0]["maxmind_asn_name"] == "Google LLC"
    assert deetlist[0]["maxmind_country_code"] == "US"
    assert deetlist[0]["maxmind_country_name"] == "United States"

    assert deetlist[1]["ip"] == "1.1.1.1"
    assert deetlist[1]["input_type"] == "ip"
    assert deetlist[1]["reverse_dns"] == "one.one.one.one"
    assert deetlist[1]["maxmind_asn_name"] == "Cloudflare, Inc."
    assert deetlist[1]["maxmind_country_code"] == "AU"
    assert deetlist[1]["maxmind_country_name"] == "Australia"
示例#4
0
def test_input_is_what():
    ii = IpInfo()
    assert ii.input_is_what("8.8.8.8") == "ip"
    assert ii.input_is_what(" 8.8.8.8 ") == "ip"
    assert ii.input_is_what("dns.google") == "domain"
    assert ii.input_is_what("asdfasdf") == "unknown"
示例#5
0
def test_ipinfo_is_ip_valid():
    ii = IpInfo()
    assert ii.is_ip_valid(1)
    assert ii.is_ip_valid("127.0.0.1")
    assert ii.is_ip_valid("8.8.8.8")
    assert not ii.is_ip_valid("s")
示例#6
0
def test_input_to_ip():
    ii = IpInfo()
    g_ip = ii.input_to_ip("dns.google")
    assert g_ip == "8.8.8.8" or g_ip == "8.8.4.4"
示例#7
0
def test_ip_to_reverse_dns():
    ii = IpInfo()
    assert ii.ip_to_reverse_dns("1.1.1.1") == "one.one.one.one"
    assert ii.ip_to_reverse_dns("8.8.8.8") == "dns.google"
示例#8
0
def test_ip_to_asn_name():
    ii = IpInfo()
    assert ii.ip_to_asn_name("8.8.8.8") == "Google LLC"
    assert ii.ip_to_asn_name("8dfs.8.8.8") == ""
示例#9
0
def test_ipinfo_get_meta():
    ii = IpInfo()
    meta_str = ii.get_meta()
    assert len(meta_str) == 55
    assert meta_str.startswith("GeoLite2-ASN_")
示例#10
0
def test_domain_to_ip_full():
    ii = IpInfo()
    cf = ii.domain_to_ip_full("one.one.one.one")
    assert len(cf) == 2
    for cf_ip in cf:
        assert cf_ip == "1.1.1.1" or cf_ip == "1.0.0.1"
示例#11
0
def test_domain_to_ip():
    ii = IpInfo()
    g_ip = ii.domain_to_ip("dns.google")
    assert g_ip == "8.8.8.8" or g_ip == "8.8.4.4"
    cf_ip = ii.domain_to_ip("one.one.one.one")
    assert cf_ip == "1.1.1.1" or cf_ip == "1.0.0.1"
示例#12
0
def test_ip_to_country_name():
    ii = IpInfo()
    assert ii.ip_to_country_name("8.8.8.8") == "United States"
    assert ii.ip_to_country_name("2.57.168.0") == "Canada"
示例#13
0
def test_ip_to_country_code():
    ii = IpInfo()
    assert ii.ip_to_country_code("8.8.8.8") == "US"
    assert ii.ip_to_country_code("2.57.168.0") == "CA"
示例#14
0
def test_ipinfo_init():
    ii = IpInfo()
    assert ii
示例#15
0
def test_ipinfo_is_ip_private():
    ii = IpInfo()
    assert ii.is_ip_private("127.0.0.1")
    assert not ii.is_ip_private("8.8.8.8")
    assert not ii.is_ip_private("asfdasfd")
示例#16
0
文件: praytimes.py 项目: hajtux/salat
        if math.isnan(a):
            return a
        a = a - mode * (math.floor(a / mode))
        return a + mode if a < 0 else a


#---------------------- prayTimes Object -----------------------

prayTimes = PrayTimes()

#-------------------------- Test Code --------------------------

# sample code to run in standalone mode only
if __name__ == "__main__":
    from datetime import date
    ipinfo = IpInfo()
    pt = PrayTimes()
    pt.setMethod('UOIF')
    print(
        '\nPrayer Times for today in %s with %s methode calculation\n' %
        (ipinfo.getCity(), pt.calcMethod) + ('=' * 41))
    times = pt.getTimes(date.today(),
                        (ipinfo.getLongitude(), ipinfo.getLatitude()), +1)
    for i in [
            'Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'
    ]:
        print(i + ': ' + times[i.lower()])
    print
    print "Next Salat : "
    print('=' * 41)
    print pt.nextSalat((ipinfo.getLongitude(), ipinfo.getLatitude()), +1)
示例#17
0
def test_ip_to_asn_num():
    ii = IpInfo()
    assert ii.ip_to_asn_num("8.8.8.8") == 15169
    assert ii.ip_to_asn_num("8.8.df8.8") == -1