本文整理匯總了Python中netaddr.IPAddress.is_ipv4_compat方法的典型用法代碼示例。如果您正苦於以下問題:Python IPAddress.is_ipv4_compat方法的具體用法?Python IPAddress.is_ipv4_compat怎麽用?Python IPAddress.is_ipv4_compat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類netaddr.IPAddress
的用法示例。
在下文中一共展示了IPAddress.is_ipv4_compat方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: normalize_mapped_address
# 需要導入模塊: from netaddr import IPAddress [as 別名]
# 或者: from netaddr.IPAddress import is_ipv4_compat [as 別名]
def normalize_mapped_address(ipaddr):
"""
Converts a IPv4-mapped IPv6 address into a IPv4 address. Handles both the
::ffff:192.0.2.128 format as well as the deprecated ::192.0.2.128 format.
:param ipaddr: IP address [str]
:return: normalized IP address [str]
"""
ipaddr = IPAddress(ipaddr)
if ipaddr.is_ipv4_compat() or ipaddr.is_ipv4_mapped():
ipaddr = ipaddr.ipv4()
return str(ipaddr)
示例2: test_ip_v4_to_ipv6_mapped
# 需要導入模塊: from netaddr import IPAddress [as 別名]
# 或者: from netaddr.IPAddress import is_ipv4_compat [as 別名]
def test_ip_v4_to_ipv6_mapped():
ip = IPAddress('192.0.2.15').ipv6()
assert ip == IPAddress('::ffff:192.0.2.15')
assert ip.is_ipv4_mapped()
assert not ip.is_ipv4_compat()