diff options
-rw-r--r-- | ipv6.py | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -5,6 +5,9 @@ from twisted.internet import default from twisted.internet import protocol from twisted.internet import reactor +from twisted.names.client import Resolver +resolver = Resolver('/etc/resolv.conf') + class IPv6Address(object): def __init__(self, type, host, port, flowInfo, scope): self.type = type @@ -38,10 +41,17 @@ class Client(tcp.Client): if isIPv6Address(self.addr[0]): self._setRealAddress(self.addr[0]) else: - reactor.resolve(self.addr[0]).addCallbacks( - self._setRealAddress, self.failIfNotConnected + resolver.lookupIPV6Address(self.addr[0]).addCallbacks( + self.resolvedAddress, self.failIfNotConnected ) + def resolvedAddress(self, addr): + aaaa = addr[0][-1].payload + if aaaa.fancybasename != 'AAAA': + self.failIfNotConnected(Exception('Unable to resolve IPv6 address.')) + return + self._setRealAddress(aaaa._address) + def getHost(self): return IPv6Address('TCP', *self.socket.getsockname()) |