當前位置: 首頁>>代碼示例>>Python>>正文


Python IPy.IP屬性代碼示例

本文整理匯總了Python中IPy.IP屬性的典型用法代碼示例。如果您正苦於以下問題:Python IPy.IP屬性的具體用法?Python IPy.IP怎麽用?Python IPy.IP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在IPy的用法示例。


在下文中一共展示了IPy.IP屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_ipv4

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def is_ipv4(ip):
    """Check if the [ip] is a real ip addr.
    
    Params:
        ip: :str: General IP format.
        
    Returns:
        :type: bool
        :desc: if ip is a valid IP addr, return true
            else return False"""
    try:
        IP(ip)
        return True
    except ValueError:
        return False

#---------------------------------------------------------------------- 
開發者ID:VillanCh,項目名稱:g3ar,代碼行數:19,代碼來源:ip_calc_utils.py

示例2: __init__

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def __init__(self, address):
        self.cached_prefix_found = False
        self.ip_object = IPy.IP(address)

        self.address = self.ip_object.strFullsize()
        self.asn = None
        self.holder = None
        self.prefix = None
        self.not_querable_types = [
            'RESERVED', 'UNSPECIFIED', 'LOOPBACK',
            'UNASSIGNED', 'DOCUMENTATION', 'ULA',
            'LINKLOCAL', 'PRIVATE'
        ]

        details = self._get_details()
        if details:
            self.asn = details["ASN"]
            self.holder = details["Holder"]
            self.prefix = details["Prefix"] 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:21,代碼來源:ipdetails.py

示例3: get_from_cached_prefix

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def get_from_cached_prefix(self):
        """Search cache for existing cached Prefix"""
        details = None

        for cache_entry in cache.keys():
            if not cache_entry.decode().startswith("IPDetailsPrefix:"):
                continue

            prefix_details = cache.get(cache_entry)

            # data could exist but expired
            if not prefix_details:
                continue

            prefix = IPy.IP(prefix_details["Prefix"])

            if self.ip_object in prefix:
                details = prefix_details
                self.cached_prefix_found = True
                break

        return details 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:24,代碼來源:ipdetails.py

示例4: probe_port

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def probe_port(self, port, protocol, ip):
        self.logger.info('probing {0}'.format(port))
        url = urljoin(self.redirect_api_url, "/probe/port_v2")
        try:
            request = {'token': self.update_token, 'port': port, 'protocol': protocol}
            if ip:
                iptype=IP(ip).iptype()
                if iptype != 'PUBLIC':
                    return False, 'IP: {0} is not public'.format(ip)
                request['ip'] = ip

            response = requests.get(url, params=request)
            self.logger.info('response status_code: {0}'.format(response.status_code))
            self.logger.info('response text: {0}'.format(response.text))
            result = json.loads(response.text)
            if response.status_code == 200 and result['message'] == 'OK':
                return True, ''
            else:
                external_device_ip = result['device_ip']
                ip_version = IP(external_device_ip).version()
                return False, 'using device public IP: "{0}" which is IPv{1}'.format(external_device_ip, ip_version)
                    
        except Exception as e:
            self.logger.info('{0} is not reachable, error: {1}'.format(port, str(e)))
            return False, 'unable to validate external port: {0}'.format(str(e)) 
開發者ID:syncloud,項目名稱:platform,代碼行數:27,代碼來源:port_prober.py

示例5: is_pingable

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def is_pingable(ip):
    """
    Ping the target IP
    :param ip:
    :return:
    """
    try:
        # Ping parameters as function of OS
        ping_str = "-n 1 -w 500" if platform.system().lower() == "windows" else "-c 1 -W 500"
        # Ping
        subprocess.check_output("ping {0} {1}".format(ping_str, ip),
                                stderr=subprocess.STDOUT,
                                shell=True)
        return True
    except Exception as e:
        # traceback.print_exc()
        return False 
開發者ID:Neo23x0,項目名稱:munin,代碼行數:19,代碼來源:munin-host.py

示例6: VerifyIp

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def VerifyIp(ip):

	ip_type = None

	try:

		ip_type = IP(ip).iptype()

		if ip_type is not "PUBLIC":

			ip_type = 'Private'

		else:

			ip_type = 'Public'

	except Exception:
		
		pass

	finally:

		return ip_type 
開發者ID:n4xh4ck5,項目名稱:N4xD0rk,代碼行數:25,代碼來源:verifyip.py

示例7: is_pingable

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def is_pingable(ip):
    """
    Ping the target IP
    :param ip:
    :return:
    """
    try:
        # Ping parameters as function of OS
        ping_str = "-n 1 -w 500" if platform.system().lower() == "windows" else "-c 1 -W 500"
        # Ping
        subprocess.check_output("ping {0} {1}".format(ping_str, ip),
                                stderr=subprocess.STDOUT,
                                shell=True)
        return True
    except Exception, e:
        # traceback.print_exc()
        return False 
開發者ID:Neo23x0,項目名稱:Loki,代碼行數:19,代碼來源:vt-checker-hosts.py

示例8: testCheckPrefixOk

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def testCheckPrefixOk(self):
        """Legal IP/prefix combinations should check ok."""
        self.assertTrue(IPy._checkPrefix(0x0, 32, 4))
        self.assertTrue(IPy._checkPrefix(0xffffffff, 32, 4))
        self.assertTrue(IPy._checkPrefix(0x7f000001, 32, 4))
        self.assertTrue(IPy._checkPrefix(0x80000000, 1, 4))
        self.assertTrue(IPy._checkPrefix(0x40000000, 2, 4))
        self.assertTrue(IPy._checkPrefix(0x80000000, 3, 4))
        self.assertTrue(IPy._checkPrefix(0x80000000, 4, 4))
        self.assertTrue(IPy._checkPrefix(0xffffff00, 24, 4))
        self.assertTrue(IPy._checkPrefix(0xffffff00, 24, 4))
        self.assertTrue(IPy._checkPrefix(0xfffffff0, 28, 4))
        self.assertTrue(IPy._checkPrefix(0x0, 32, 4))
        self.assertTrue(IPy._checkPrefix(0x0, 1, 4))
        self.assertTrue(IPy._checkPrefix(0x0, 0, 4))
        self.assertTrue(IPy._checkPrefix(0xffffffffffffffff0000000000000000, 64, 6))
        self.assertTrue(IPy._checkPrefix(0x0, 64, 6))
        self.assertTrue(IPy._checkPrefix(0x0, 0, 6))
        self.assertTrue(IPy._checkPrefix(0x0, 128, 6))
        self.assertTrue(IPy._checkPrefix(0xffffffffffffffffffffffffffffffff, 128, 6)) 
開發者ID:H4ckForJob,項目名稱:dirmap,代碼行數:22,代碼來源:test_IPy.py

示例9: testIfComparesEqual

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def testIfComparesEqual(self):
        """nets of the same base and size should be considered equal, others not"""
        a = IPy.IP('127.0.0.0/24')
        a2 = a
        b = IPy.IP('127.0.0.0/24')
        c = IPy.IP('127.0.0.0/23')
        d = IPy.IP('127.0.0.0/22')
        e = IPy.IP('64.0.0.0/24')
        self.assertEqual(a2, a)
        self.assertEqual(a2, b)
        self.assertEqual(a, a)
        self.assertEqual(a, b)
        self.assertNotEqual(a, c)
        self.assertNotEqual(a, d)
        self.assertNotEqual(a, e)
        self.assertNotEqual(b, c)
        self.assertNotEqual(b, d)
        self.assertNotEqual(b, e)
        self.assertNotEqual(c, d)
        self.assertNotEqual(c, e)
        self.assertNotEqual(d, e) 
開發者ID:H4ckForJob,項目名稱:dirmap,代碼行數:23,代碼來源:test_IPy.py

示例10: testStrBin

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def testStrBin(self):
        """Binary string Output."""

        testValues = [('0.0.0.0', '00000000000000000000000000000000'),
                      ('0.0.0.1', '00000000000000000000000000000001'),
                      ('255.255.255.255', '11111111111111111111111111111111'),
                      ('128.0.0.0', '10000000000000000000000000000000'),
                      ('::0', '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'),
                      ('::1', '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001'),
                      ('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'),
                      ('5555:5555:5555:5555:5555:5555:5555:5555', '01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101'),
                      ('aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa', '10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010'),
                      ('85.85.85.85', '01010101010101010101010101010101'),
                      ('170.170.170.170', '10101010101010101010101010101010'),
                      ('127.0.0.1', '01111111000000000000000000000001'),
                      ('1::2:0:0:3', '00000000000000010000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000011')]
        for (question, answer) in testValues:
            result = IPy.IP(question).strBin()
            self.assertEqual(answer, result, (question, answer, result)) 
開發者ID:H4ckForJob,項目名稱:dirmap,代碼行數:21,代碼來源:test_IPy.py

示例11: __str__

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def __str__(self):
        return "IP {}, ASN {}, Holder {}".format(
            self.address, self.asn, self.holder
        ) 
開發者ID:RIPE-NCC,項目名稱:ripe-atlas-tools,代碼行數:6,代碼來源:ipdetails.py

示例12: ip_type

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def ip_type(ip):
    return IP(ip).iptype() 
開發者ID:syncloud,項目名稱:platform,代碼行數:4,代碼來源:linux.py

示例13: findnametodns

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def findnametodns(self,qname,nametodns):

        # Make qname case insensitive
        qname = qname.lower()
    
        # Split and reverse qname into components for matching.
        qnamelist = qname.split('.')
        qnamelist.reverse()
    
        # HACK: It is important to search the nametodns dictionary before iterating it so that
        # global matching ['*.*.*.*.*.*.*.*.*.*'] will match last. Use sorting for that.
        for domain,host in sorted(nametodns.iteritems(), key=operator.itemgetter(1)):

            # NOTE: It is assumed that domain name was already lowercased
            #       when it was loaded through --file, --fakedomains or --truedomains
            #       don't want to waste time lowercasing domains on every request.

            # Split and reverse domain into components for matching
            domain = domain.split('.')
            domain.reverse()
            
            # Compare domains in reverse.
            for a,b in map(None,qnamelist,domain):
                if a != b and b != "*":
                    break
            else:
                # Could be a real IP or False if we are doing reverse matching with 'truedomains'
                return host
        else:
            return False
    
    # Obtain a response from a real DNS server. 
開發者ID:GoSecure,項目名稱:break-fast-serial,代碼行數:34,代碼來源:dnschef.py

示例14: get_ip_list

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def get_ip_list(self, ips):
        """Generates the list of ips to reverse"""
        try:
            list = IPy.IP(ips)
        except:
            print "Error in IP format, check the input and try again. (Eg. 192.168.1.0/24)"
            sys.exit()
        name = []
        for x in list:
            name.append(str(x))
        return name 
開發者ID:Yukinoshita47,項目名稱:Yuki-Chan-The-Auto-Pentest,代碼行數:13,代碼來源:dnssearch-threads.py

示例15: checkTTL

# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def checkTTL(ipsrc, ttl):
    if IPTEST(ipsrc).iptype() == 'PRIVATE':
        return
    if not ttlvalues.has_key(ipsrc):
        pkt = sr1(IP(dst=ipsrc) / ICMP(), retry=0, timeout=1, verbose=0)
        ttlvalues[ipsrc] = pkt.ttl

    if abs(int(ttl) - int(ttlvalues[ipsrc])) > THRESH:
        print '\n[!] Detected Possible Spoofed Packet From: ' + ipsrc
        print '[!] TTL: ' + ttl + ', Actual TTL: ' + str(ttlvalues[ipsrc])

#解析收到的數據包的源ip和ttl 
開發者ID:sunshinelyz,項目名稱:python-hacker,代碼行數:14,代碼來源:scapy_ip_ttl.py


注:本文中的IPy.IP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。