本文整理匯總了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
#----------------------------------------------------------------------
示例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"]
示例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
示例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))
示例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
示例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
示例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
示例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))
示例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)
示例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))
示例11: __str__
# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def __str__(self):
return "IP {}, ASN {}, Holder {}".format(
self.address, self.asn, self.holder
)
示例12: ip_type
# 需要導入模塊: import IPy [as 別名]
# 或者: from IPy import IP [as 別名]
def ip_type(ip):
return IP(ip).iptype()
示例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.
示例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
示例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