mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Socket: Forward DNS queries via the socks proxy (if any).
This commit is contained in:
parent
921ff2ae07
commit
dd37f8dd3f
@ -267,24 +267,28 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
||||
else:
|
||||
drivers.log.debug('Not resetting %s.', self.irc)
|
||||
server = self._getNextServer()
|
||||
socks_proxy = getattr(conf.supybot.networks, self.irc.network) \
|
||||
.socksproxy()
|
||||
resolver = None
|
||||
try:
|
||||
address = utils.net.getAddressFromHostname(server[0],
|
||||
attempt=self._attempt)
|
||||
except socket.gaierror as e:
|
||||
drivers.log.connectError(self.currentServer, e)
|
||||
self.scheduleReconnect()
|
||||
return
|
||||
if socks_proxy:
|
||||
import socks
|
||||
except ImportError:
|
||||
log.error('Cannot use socks proxy (SocksiPy not installed), '
|
||||
'using direct connection instead.')
|
||||
socks_proxy = ''
|
||||
if socks_proxy:
|
||||
address = server[0]
|
||||
else:
|
||||
try:
|
||||
address = utils.net.getAddressFromHostname(server[0],
|
||||
attempt=self._attempt)
|
||||
except socket.gaierror as e:
|
||||
drivers.log.connectError(self.currentServer, e)
|
||||
self.scheduleReconnect()
|
||||
return
|
||||
drivers.log.connect(self.currentServer)
|
||||
try:
|
||||
socks_proxy = getattr(conf.supybot.networks, self.irc.network) \
|
||||
.socksproxy()
|
||||
try:
|
||||
if socks_proxy:
|
||||
import socks
|
||||
except ImportError:
|
||||
log.error('Cannot use socks proxy (SocksiPy not installed), '
|
||||
'using direct connection instead.')
|
||||
socks_proxy = ''
|
||||
self.conn = utils.net.getSocket(address, socks_proxy)
|
||||
vhost = conf.supybot.protocols.irc.vhost()
|
||||
self.conn.bind((vhost, 0))
|
||||
|
@ -92,13 +92,15 @@ def getSocket(host, socks_proxy=None):
|
||||
"""Returns a socket of the correct AF_INET type (v4 or v6) in order to
|
||||
communicate with host.
|
||||
"""
|
||||
addrinfo = socket.getaddrinfo(host, None)
|
||||
host = addrinfo[0][4][0]
|
||||
if not socks_proxy:
|
||||
addrinfo = socket.getaddrinfo(host, None)
|
||||
host = addrinfo[0][4][0]
|
||||
if socks_proxy:
|
||||
import socks
|
||||
s = socks.socksocket()
|
||||
hostname, port = socks_proxy.rsplit(':', 1)
|
||||
s.setproxy(socks.PROXY_TYPE_SOCKS5, hostname, int(port))
|
||||
s.setproxy(socks.PROXY_TYPE_SOCKS5, hostname, int(port),
|
||||
rdns=True)
|
||||
return s
|
||||
if isIPV4(host):
|
||||
return socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
Loading…
Reference in New Issue
Block a user