本文整理汇总了Python中IPy类的典型用法代码示例。如果您正苦于以下问题:Python IPy类的具体用法?Python IPy怎么用?Python IPy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRandomValuesv6
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))
示例2: mod_change_cache
def mod_change_cache(zona=None, rr=None, rtype=None, ttl=1800, data=None, action=None, username=None, del_id=None, operation=None):
"""Modify the publish queue"""
zone_id = zones.select().where(zones.zone == zona).get()
if rtype == "A" or rtype == "NS":
try:
IPy.parseAddress(data)
except ValueError:
return False
if operation == "add_unpub":
for item in [zona, rr, rtype, ttl, data, action, operation]:
if item is None:
return False
if change_cache.select().where(change_cache.rr == rr,
change_cache.zone_id == zone_id,
change_cache.type == rtype,
change_cache.data == data,
change_cache.action == "add").count():
return True
change_cache.create(username=username,
rr=rr,
zone_id=zone_id,
type=rtype,
ttl=ttl,
data=data,
action=action)
return True
elif operation == "del_unpub":
delete_query = change_cache.delete().where((change_cache.id == del_id) & (change_cache.zone_id == zone_id))
delete_query.execute()
return True
示例3: testCheckNetmaskOk
def testCheckNetmaskOk(self):
"""Legal Netmasks should be allowed."""
self.assertFalse(IPy._checkNetmask(0xffffffff, 32))
self.assertFalse(IPy._checkNetmask(0xffffff00, 32))
self.assertFalse(IPy._checkNetmask(0xffff0000, 32))
self.assertFalse(IPy._checkNetmask(0xff000000, 32))
self.assertFalse(IPy._checkNetmask(0, 32))
示例4: multi_ipcheck
def multi_ipcheck(form, field):
error = []
for x in field.data.split():
try:
IPy.parseAddress(x)
except ValueError:
error.append( x )
if error:
raise ValidationError( _('Error IP: %s') % error )
示例5: testCheckNetmaskOk
def testCheckNetmaskOk(self):
"""Legal Netmasks should be allowed."""
self.failIf(IPy._checkNetmask(0xFFFFFFFFL, 32))
self.failIf(IPy._checkNetmask(0xFFFFFF00L, 32))
self.failIf(IPy._checkNetmask(0xFFFF0000L, 32))
self.failIf(IPy._checkNetmask(0xFF000000L, 32))
self.failIf(IPy._checkNetmask(0, 32))
示例6: testCount1Bits
def testCount1Bits(self):
self.assertEqual(IPy._count1Bits(0), 0)
self.assertEqual(IPy._count1Bits(0xF), 4)
self.assertEqual(IPy._count1Bits(0x10), 5)
self.assertEqual(IPy._count1Bits(0xFF), 8)
self.assertEqual(IPy._count1Bits(0xFFFF), 16)
self.assertEqual(IPy._count1Bits(0xFFFFFFFFL), 32)
self.assertEqual(IPy._count1Bits(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL), 128)
示例7: makeIpPool
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)}
示例8: check_ip_address
def check_ip_address(address, version=None):
try:
_ip, ver = IPy.parseAddress(address)
except ValueError:
return False
if version and version == ver:
return True
示例9: ip_version_validator
def ip_version_validator(value, version, message):
try:
ip, v = IPy.parseAddress(value)
except ValueError:
raise forms.ValidationError(message)
if v != version:
raise forms.ValidationError(message)
示例10: IP_int_prefixlen
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))
示例11: address_check
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)
示例12: creatIpPool
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
示例13: query
def query(self, sql):
print "executing sql : " + sql
self.cur.execute(sql)
alldata = self.cur.fetchall()
if alldata:
for data in alldata:
eid = IPy.parseAddress(data[0])
#print eid
print data[0], data[1]
return alldata
示例14: increment_range
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
示例15: testKnownValues
def testKnownValues(self):
"""parsing of known values should give known results"""
for x in self.okValues:
(question, answer) = x
(result, version) = IPy.parseAddress(question)
self.assertEqual(answer, result, "%r, %r, %r" % (question, answer, result))