本文整理匯總了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")