本文整理汇总了Python中netaddr.IPAddress.bits方法的典型用法代码示例。如果您正苦于以下问题:Python IPAddress.bits方法的具体用法?Python IPAddress.bits怎么用?Python IPAddress.bits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netaddr.IPAddress
的用法示例。
在下文中一共展示了IPAddress.bits方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ipaddress_v4
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import bits [as 别名]
def test_ipaddress_v4():
ip = IPAddress('192.0.2.1')
assert ip.version == 4
assert repr(ip) == "IPAddress('192.0.2.1')"
assert str(ip) == '192.0.2.1'
assert ip.format() == '192.0.2.1'
assert int(ip) == 3221225985
assert hex(ip) == '0xc0000201'
assert ip.bin == '0b11000000000000000000001000000001'
assert ip.bits() == '11000000.00000000.00000010.00000001'
assert ip.words == (192, 0, 2, 1)
示例2: test_ipaddress_v6
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import bits [as 别名]
def test_ipaddress_v6():
ip = IPAddress('fe80::dead:beef')
assert ip.version == 6
assert repr(ip) == "IPAddress('fe80::dead:beef')"
assert str(ip) == 'fe80::dead:beef'
assert ip.format() == 'fe80::dead:beef'
assert int(ip) == 338288524927261089654018896845083623151
assert hex(ip) == '0xfe8000000000000000000000deadbeef'
assert ip.bin == '0b11111110100000000000000000000000000000000000000000000000000000000000000000000000000000000000000011011110101011011011111011101111'
assert ip.bits() == '1111111010000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:1101111010101101:1011111011101111'
assert ip.words == (65152, 0, 0, 0, 0, 0, 57005, 48879)
示例3: getBits
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import bits [as 别名]
def getBits(self, netmask):
mask = IPAddress(netmask)
return mask.bits().count("1")