本文整理汇总了Python中IPy.intToIp方法的典型用法代码示例。如果您正苦于以下问题:Python IPy.intToIp方法的具体用法?Python IPy.intToIp怎么用?Python IPy.intToIp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPy
的用法示例。
在下文中一共展示了IPy.intToIp方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IP_int_prefixlen
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def IP_int_prefixlen(ipnum, prefixlen, version):
if version == 4:
width = 32
else:
width = 128
ipnum &= -(1 << (width - prefixlen))
return IP("{0}/{1}".format(IPy.intToIp(ipnum, version), prefixlen))
示例2: testRandomValuesv6
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def testRandomValuesv6(self):
for i in range(testloops):
question = ((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) +
((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) << 32) +
((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) << 64) +
((random.randrange(0x7fffffff) + random.randrange(0x7fffffff)) << 96))
self.assertEqual(IPy.parseAddress(IPy.intToIp(question, 6)), (question, 6), hex(question))
示例3: makeIpPool
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def makeIpPool(self, startIP, lastIP):
'''生产 IP 地址池'''
IPver = 6 if self.IPv6 else 4
intIP = lambda ip: IPy.IP(ip).int()
ipPool = {IPy.intToIp(ip, IPver) for ip in range(intIP(startIP), intIP(lastIP)+1)}
return {ip for ip in ipPool if self.isUnIP(ip)}
示例4: creatIpPool
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def creatIpPool(self, startIP, stopIP):
ipPool = set()
if self.isV6:
print "this function is not develop"
else:
ipToInt = lambda ip: IPy.IP(ip).int()
ipPool = {IPy.intToIp(ip, 4) for ip in range(ipToInt(startIP), ipToInt(stopIP)+1)}
return ipPool
示例5: increment_range
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def increment_range(start_ip, counter):
"""
Increment IP address by 255 multiple times
:param start_ip: base IP to be incremented
:type start_ip: str
:param counter: how many times do you want to increment the IP by 255
:return:incremented IP
"""
incremented_ip_int = IPy.IPint(start_ip).int() + counter * 255
incremented_ip_str = IPy.intToIp(ip=incremented_ip_int, version=4)
return incremented_ip_str
示例6: address_check
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def address_check(address):
'''
Check if the IP address is valid.
:param str address: IP address to check
:return: tuple of (address, version), where address is cleaned up IP address
and version is 4 for IPv4 and 6 for IPv6
:rtype: tuple of (str, int)
:raises: IPCheckFailed
'''
try:
address_int, version = IPy.parseAddress(address)
except ValueError:
raise IPCheckFailed("Invalid IP address: %s" % address)
address = IPy.intToIp(address_int, version)
return (address, version)
示例7: testRandomValuesv4
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def testRandomValuesv4(self):
for i in range(testloops):
question = long(random.randrange(0x7FFFFFFF)) + long(random.randrange(0x7FFFFFFF))
self.assertEqual(IPy.parseAddress(IPy.intToIp(question, 4)), (question, 4), hex(question))
示例8: testKnownValuesv6
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def testKnownValuesv6(self):
"""printing of known IPv6 values should give known results"""
for x in self.v6values:
(question, answer) = x
result = IPy.intToIp(question, 6).lower()
self.assertEqual(answer, result, "%r, %r, %r" % (question, answer, result))
示例9: ip
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def ip(self, if_tag=None, if_name=None, version=None):
ra_line = None
ra_suppress = False
ra_prefix = []
if_prefix = []
cmd = self.expect(Keyword)
if False:
pass
elif cmd == 'address':
name = self.accept(String)
ipaddress = self.accept(Literal)
if ipaddress:
self.accept(Punctuation) # allow detection of address/prefix length
if name:
ipaddress = IPy.intToIp(IPy.IP(ipaddress).int() | ipv6_general_prefixes[name].int(), 6)
address = ipaddress + "/" + self.expect(Literal)
if if_name:
if version == 'IPv4':
if_addrs4.setdefault(if_name, ipaddress)
elif version == 'IPv6':
if_addrs6.setdefault(if_name, ipaddress)
ifaddr_tag = taglib.ip_address_tag(address,
kind="interface address")
address_tag = taglib.ip_address_tag(address)
subnet_tag = taglib.ip_subnet_tag(address)
ifaddr_tag.implied_by(if_tag, self.lineNum)
address_tag.implied_by(ifaddr_tag, self.lineNum)
subnet_tag.implied_by(address_tag, self.lineNum)
if version:
version_tag = taglib.tag("IP version", version)
version_tag.implied_by(if_tag, self.lineNum)
# add router advertisement by default on multi-access networks
if version == 'IPv6':
ipv6_addresses = True
if re.search(r"eth|fddi|port-channel", if_tag.name, re.I):
if_prefix.append(subnet_tag.name)
ra_line = self.lineNum
self.skipTo(EndOfCommand)
elif cmd == 'cef':
if not version:
version = "IPv4"
distributed = self.accept(Keyword)
if distributed == "distributed":
cef = " ".join((version, distributed))
else:
cef = version
t = taglib.tag("Cisco express forwarding", cef)
t.implied_by(device_tag, self.lineNum)
self.skipTo(EndOfCommand)
elif cmd == 'domain name' or cmd == 'domain-name':
t = taglib.tag("domain name", self.expect(String))
t.implied_by(taglib.env_tags.device, self.lineNum)
self.expect(EndOfCommand)
elif cmd == 'general-prefix':
name = self.expect(String)
ipaddress = self.expect(Literal)
self.expect(Punctuation)
address = ipaddress + "/" + self.expect(Literal)
ipv6_general_prefixes[name] = IPy.IP(address)
self.expect(EndOfCommand)
elif cmd == 'helper-address':
t = taglib.tag("BOOTP relay", self.expect(Literal))
t.implied_by(taglib.env_tags.device, self.lineNum)
self.expect(EndOfCommand)
elif cmd == 'http':
nextCmd = self.expect(Keyword)
if nextCmd == 'server':
t = taglib.tag("service", "HTTP")
t.implied_by(taglib.env_tags.device, self.lineNum)
elif nextCmd == 'secure-server':
t = taglib.tag("service", "HTTPS")
t.implied_by(taglib.env_tags.device, self.lineNum)
self.skipTo(EndOfCommand)
elif cmd == 'name-server':
t = taglib.tag("name server", self.expect(Literal))
t.implied_by(taglib.env_tags.device, self.lineNum)
self.expect(EndOfCommand)
elif cmd == 'nd':
nextCmd = self.expect(Keyword)
if nextCmd == 'prefix':
ra_line = self.lineNum
nd_prefix = None
default_prefix = self.accept(Keyword)
if not default_prefix:
nd_prefix = self.expect(Literal) + self.expect(Punctuation) + self.expect(Literal)
keyword = self.accept(Keyword)
if keyword is None or not 'no-ad' in keyword:
if nd_prefix:
ra_prefix.append(nd_prefix)
#.........这里部分代码省略.........
示例10: testRandomValuesv6
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def testRandomValuesv6(self):
question = random.randrange(0xffffffffffffffffffffffffffffffff)
self.assertEqual(IPy.parseAddress(IPy.intToIp(question, 6)), (question, 6), hex(question))
示例11: ip
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import intToIp [as 别名]
def ip(self, if_tag=None, version=None, active=True):
ra_line = None
ra_suppress = False
ra_prefix = []
if_prefix = []
cmd = self.expect(Keyword)
if False:
pass
elif cmd == 'address':
name = self.accept(String)
ipaddress = self.accept(Literal)
if ipaddress:
self.accept(Punctuation) # allow detection of address/prefix length
if name:
ipaddress = IPy.intToIp(IPy.IP(ipaddress).int() | ipv6_general_prefixes[name].int(), 6)
address = ipaddress + "/" + self.expect(Literal)
if active:
ifaddr_tag = taglib.ip_address_tag(address,
kind="interface address")
address_tag = taglib.ip_address_tag(address)
subnet_tag = taglib.ip_subnet_tag(address)
ifaddr_tag.implied_by(if_tag, self.lineNum)
address_tag.implied_by(ifaddr_tag, self.lineNum)
subnet_tag.implied_by(address_tag, self.lineNum)
if version:
version_tag = taglib.tag("IP version", version)
version_tag.implied_by(if_tag, self.lineNum)
# add router advertisement by default on multi-access networks
if version == 'IPv6' and re.search(r"eth|srp", if_tag.name, re.I):
if_prefix.append(subnet_tag.name)
ra_line = self.lineNum
self.skipTo(EndOfCommand)
elif cmd == 'general-prefix':
name = self.expect(String)
ipaddress = self.expect(Literal)
self.expect(Punctuation)
address = ipaddress + "/" + self.expect(Literal)
ipv6_general_prefixes[name] = IPy.IP(address)
self.expect(EndOfCommand)
elif cmd == 'helper-address':
if self.accept(Keyword):
self.expect(Literal)
t = taglib.tag("BOOTP relay", self.expect(Literal))
t.implied_by(taglib.env_tags.device, self.lineNum)
self.expect(EndOfCommand)
elif cmd == 'http':
nextCmd = self.expect(Keyword)
if nextCmd == 'server':
t = taglib.tag("service", "HTTP")
t.implied_by(taglib.env_tags.device, self.lineNum)
elif nextCmd == 'secure-server':
t = taglib.tag("service", "HTTPS")
t.implied_by(taglib.env_tags.device, self.lineNum)
self.skipTo(EndOfCommand)
elif cmd == 'nd':
nextCmd = self.expect(Keyword)
if nextCmd == 'prefix':
nd_prefix = None
default_prefix = self.accept(Keyword)
if not default_prefix:
nd_prefix = self.expect(Literal) + self.expect(Punctuation) + self.expect(Literal)
keyword = self.accept(Keyword)
if keyword is None or not 'no-ad' in keyword:
if nd_prefix:
ra_prefix.append(nd_prefix)
elif nextCmd == 'suppress-ra':
ra_suppress = True
self.skipTo(EndOfCommand)
elif cmd == 'scp':
nextCmd = self.expect(Keyword)
if nextCmd == 'server':
nextCmd = self.expect(Keyword)
if nextCmd == 'enable':
t = taglib.tag("service", taglib.protocol_name(cmd))
t.implied_by(taglib.env_tags.device, self.lineNum)
self.skipTo(EndOfCommand)
else:
self.skipTo(EndOfCommand)
return (ra_suppress, ra_line, if_prefix, ra_prefix)