本文整理汇总了Python中ipaddress.IPv6Interface方法的典型用法代码示例。如果您正苦于以下问题:Python ipaddress.IPv6Interface方法的具体用法?Python ipaddress.IPv6Interface怎么用?Python ipaddress.IPv6Interface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipaddress
的用法示例。
在下文中一共展示了ipaddress.IPv6Interface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testIpFromInt
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def testIpFromInt(self):
self.assertEqual(self.ipv4_interface._ip,
ipaddress.IPv4Interface(16909060)._ip)
ipv4 = ipaddress.ip_network('1.2.3.4')
ipv6 = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1')
self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4.network_address)))
self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6.network_address)))
v6_int = 42540616829182469433547762482097946625
self.assertEqual(self.ipv6_interface._ip,
ipaddress.IPv6Interface(v6_int)._ip)
self.assertEqual(ipaddress.ip_network(self.ipv4_address._ip).version,
4)
self.assertEqual(ipaddress.ip_network(self.ipv6_address._ip).version,
6)
示例2: testEqual
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def testEqual(self):
self.assertTrue(self.ipv4_interface ==
ipaddress.IPv4Interface('1.2.3.4/24'))
self.assertFalse(self.ipv4_interface ==
ipaddress.IPv4Interface('1.2.3.4/23'))
self.assertFalse(self.ipv4_interface ==
ipaddress.IPv6Interface('::1.2.3.4/24'))
self.assertFalse(self.ipv4_interface == '')
self.assertFalse(self.ipv4_interface == [])
self.assertFalse(self.ipv4_interface == 2)
self.assertTrue(self.ipv6_interface ==
ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/64'))
self.assertFalse(self.ipv6_interface ==
ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/63'))
self.assertFalse(self.ipv6_interface ==
ipaddress.IPv4Interface('1.2.3.4/23'))
self.assertFalse(self.ipv6_interface == '')
self.assertFalse(self.ipv6_interface == [])
self.assertFalse(self.ipv6_interface == 2)
示例3: __init__
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def __init__(self, if1: IPIntf, if2: IPIntf,
if1address: Union[str, IPv4Interface, IPv6Interface],
if2address: Union[str, IPv4Interface, IPv6Interface],
bidirectional=True):
""":param if1: The first interface of the tunnel
:param if2: The second interface of the tunnel
:param if1address: The ip_interface address for if1
:param if2address: The ip_interface address for if2
:param bidirectional: Whether both end of the tunnel should be
established or not. GRE is stateless so there is
no handshake per-say, however if one end of the
tunnel is not established, the kernel will drop
by default the encapsulated packets."""
self.if1, self.if2 = if1, if2
self.ip1, self.gre1 = (ip_interface(str(if1address)),
self._gre_name(if1))
self.ip2, self.gre2 = (ip_interface(str(if2address)),
self._gre_name(if2))
self.bidirectional = bidirectional
self.setup_tunnel()
示例4: _str_conf
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def _str_conf(self, conf_v):
if isinstance(conf_v, (bool, str, int)):
return conf_v
if isinstance(conf_v, (
ipaddress.IPv4Address, ipaddress.IPv4Interface, ipaddress.IPv4Network,
ipaddress.IPv6Address, ipaddress.IPv6Interface, ipaddress.IPv6Network)):
return str(conf_v)
if isinstance(conf_v, (dict, OrderedDict)):
return {str(i): self._str_conf(j) for i, j in conf_v.items() if j is not None}
if isinstance(conf_v, (list, tuple, frozenset)):
return tuple([self._str_conf(i) for i in conf_v if i is not None])
if isinstance(conf_v, Conf):
for i in ('name', '_id'):
if hasattr(conf_v, i):
return getattr(conf_v, i)
return None
示例5: to_ip
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def to_ip(data, *args):
# for py2 support need to convert data to unicode:
if _ttp_["python_major_version"] is 2:
ipaddr_data = unicode(data)
elif _ttp_["python_major_version"] is 3:
ipaddr_data = data
if "ipv4" in args:
if "/" in ipaddr_data or " " in ipaddr_data:
return ipaddress.IPv4Interface(ipaddr_data.replace(" ", "/")), None
else:
return ipaddress.IPv4Address(ipaddr_data), None
elif "ipv6" in args:
if "/" in ipaddr_data:
return ipaddress.IPv6Interface(ipaddr_data), None
else:
return ipaddress.IPv6Address(ipaddr_data), None
elif "/" in ipaddr_data or " " in ipaddr_data:
return ipaddress.ip_interface(ipaddr_data.replace(" ", "/")), None
else:
return ipaddress.ip_address(ipaddr_data), None
示例6: get_interface
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def get_interface(ip_address: Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]) \
-> Union[ipaddress.IPv4Interface, ipaddress.IPv6Interface]:
"""tries to find the network interface that connects to the given host's address"""
if isinstance(ip_address, str):
ip_address = get_ip_address(ip_address)
family = socket.AF_INET if ip_address.version == 4 else socket.AF_INET6
with socket.socket(family, socket.SOCK_DGRAM) as sock:
sock.connect((str(ip_address), 53)) # 53=dns
return ipaddress.ip_interface(sock.getsockname()[0])
示例7: register_ipaddress
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def register_ipaddress(conn_or_curs=None):
"""
Register conversion support between `ipaddress` objects and `network types`__.
:param conn_or_curs: the scope where to register the type casters.
If `!None` register them globally.
After the function is called, PostgreSQL :sql:`inet` values will be
converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface`
objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or
`~ipaddress.IPv6Network`.
.. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html
"""
global ipaddress
import ipaddress
global _casters
if _casters is None:
_casters = _make_casters()
for c in _casters:
register_type(c, conn_or_curs)
for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface,
ipaddress.IPv4Network, ipaddress.IPv6Network]:
register_adapter(t, adapt_ipaddress)
示例8: __new__
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def __new__(cls, *args, **kwargs):
factory_cls = cls
if cls is IPNeighbor:
if not kwargs and len(args) == 1 \
and isinstance(args[0], IPNeighbor):
# Copy constructor
factory_cls = type(args[0])
else:
if not kwargs and len(args) == 1:
ip = args[0]
else:
try:
ip = kwargs['ip']
except KeyError:
raise TypeError('\'ip\' argument missing')
if isinstance(ip, (ipaddress.IPv4Interface,
ipaddress.IPv6Interface)):
ip = ip.ip
elif isinstance(ip, (ipaddress.IPv4Address,
ipaddress.IPv6Address)):
pass
else:
ip = ipaddress.ip_address(ip)
if isinstance(ip, ipaddress.IPv4Address):
factory_cls = IPv4Neighbor
elif isinstance(ip, ipaddress.IPv6Address):
factory_cls = IPv6Neighbor
else:
raise ValueError(ip)
if factory_cls is not cls:
self = factory_cls.__new__(factory_cls, *args, **kwargs)
elif super().__new__ is object.__new__:
self = super().__new__(factory_cls)
else:
self = super().__new__(factory_cls, *args, **kwargs)
return self
示例9: __init__
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def __init__(self, ip, **kwargs):
if isinstance(ip, (ipaddress.IPv4Interface, ipaddress.IPv6Interface)):
ip = ip.ip
elif isinstance(ip, (ipaddress.IPv4Address, ipaddress.IPv6Address)):
pass
else:
ip = ipaddress.ip_address(ip)
self._ip = ip
super().__init__(**kwargs)
示例10: setUp
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def setUp(self):
self.ipv4_address = ipaddress.IPv4Address('1.2.3.4')
self.ipv4_interface = ipaddress.IPv4Interface('1.2.3.4/24')
self.ipv4_network = ipaddress.IPv4Network('1.2.3.0/24')
#self.ipv4_hostmask = ipaddress.IPv4Interface('10.0.0.1/0.255.255.255')
self.ipv6_address = ipaddress.IPv6Interface(
'2001:658:22a:cafe:200:0:0:1')
self.ipv6_interface = ipaddress.IPv6Interface(
'2001:658:22a:cafe:200:0:0:1/64')
self.ipv6_network = ipaddress.IPv6Network('2001:658:22a:cafe::/64')
示例11: testRepr
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def testRepr(self):
self.assertEqual("IPv4Interface('1.2.3.4/32')",
repr(ipaddress.IPv4Interface('1.2.3.4')))
self.assertEqual("IPv6Interface('::1/128')",
repr(ipaddress.IPv6Interface('::1')))
# issue #16531: constructing IPv4Network from a (address, mask) tuple
示例12: testZeroNetmask
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def testZeroNetmask(self):
ipv4_zero_netmask = ipaddress.IPv4Interface('1.2.3.4/0')
self.assertEqual(int(ipv4_zero_netmask.network.netmask), 0)
self.assertEqual(ipv4_zero_netmask._prefix_from_prefix_string('0'), 0)
self.assertTrue(ipv4_zero_netmask._is_valid_netmask('0'))
self.assertTrue(ipv4_zero_netmask._is_valid_netmask('0.0.0.0'))
self.assertFalse(ipv4_zero_netmask._is_valid_netmask('invalid'))
ipv6_zero_netmask = ipaddress.IPv6Interface('::1/0')
self.assertEqual(int(ipv6_zero_netmask.network.netmask), 0)
self.assertEqual(ipv6_zero_netmask._prefix_from_prefix_string('0'), 0)
示例13: testNotEqual
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def testNotEqual(self):
self.assertFalse(self.ipv4_interface !=
ipaddress.IPv4Interface('1.2.3.4/24'))
self.assertTrue(self.ipv4_interface !=
ipaddress.IPv4Interface('1.2.3.4/23'))
self.assertTrue(self.ipv4_interface !=
ipaddress.IPv6Interface('::1.2.3.4/24'))
self.assertTrue(self.ipv4_interface != '')
self.assertTrue(self.ipv4_interface != [])
self.assertTrue(self.ipv4_interface != 2)
self.assertTrue(self.ipv4_address !=
ipaddress.IPv4Address('1.2.3.5'))
self.assertTrue(self.ipv4_address != '')
self.assertTrue(self.ipv4_address != [])
self.assertTrue(self.ipv4_address != 2)
self.assertFalse(self.ipv6_interface !=
ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/64'))
self.assertTrue(self.ipv6_interface !=
ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/63'))
self.assertTrue(self.ipv6_interface !=
ipaddress.IPv4Interface('1.2.3.4/23'))
self.assertTrue(self.ipv6_interface != '')
self.assertTrue(self.ipv6_interface != [])
self.assertTrue(self.ipv6_interface != 2)
self.assertTrue(self.ipv6_address !=
ipaddress.IPv4Address('1.2.3.4'))
self.assertTrue(self.ipv6_address != '')
self.assertTrue(self.ipv6_address != [])
self.assertTrue(self.ipv6_address != 2)
示例14: testSlash128Constructor
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def testSlash128Constructor(self):
self.assertEqual(str(ipaddress.IPv6Interface('::1/128')),
'::1/128')
示例15: testEmbeddedIpv4
# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Interface [as 别名]
def testEmbeddedIpv4(self):
ipv4_string = '192.168.0.1'
ipv4 = ipaddress.IPv4Interface(ipv4_string)
v4compat_ipv6 = ipaddress.IPv6Interface('::%s' % ipv4_string)
self.assertEqual(int(v4compat_ipv6.ip), int(ipv4.ip))
v4mapped_ipv6 = ipaddress.IPv6Interface('::ffff:%s' % ipv4_string)
self.assertNotEqual(v4mapped_ipv6.ip, ipv4.ip)
self.assertRaises(ipaddress.AddressValueError, ipaddress.IPv6Interface,
'2001:1.1.1.1:1.1.1.1')
# Issue 67: IPv6 with embedded IPv4 address not recognized.