def test_v4mapped(self):
greendns.resolve = _make_mock_resolve()
greendns.resolve.add('example.com', '1.2.3.4')
res = greendns.getaddrinfo('example.com', 80,
socket.AF_INET6, 0, 0, socket.AI_V4MAPPED)
addrs = set(ai[-1] for ai in res)
assert addrs == set([('::ffff:1.2.3.4', 80, 0, 0)])
python类AI_V4MAPPED的实例源码
def test_v4mapped_all(self):
greendns.resolve = _make_mock_resolve()
greendns.resolve.add('example.com', '1.2.3.4')
greendns.resolve.add('example.com', 'dead:beef::1')
res = greendns.getaddrinfo('example.com', 80, socket.AF_INET6, 0, 0,
socket.AI_V4MAPPED | socket.AI_ALL)
addrs = set(ai[-1] for ai in res)
for addr in addrs:
assert addr in [('::ffff:1.2.3.4', 80, 0, 0),
('dead:beef::1', 80, 0, 0)]