mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Socket: Forward DNS queries via the socks proxy (if any).
This commit is contained in:
parent
921ff2ae07
commit
dd37f8dd3f
@ -267,6 +267,19 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
|||||||
else:
|
else:
|
||||||
drivers.log.debug('Not resetting %s.', self.irc)
|
drivers.log.debug('Not resetting %s.', self.irc)
|
||||||
server = self._getNextServer()
|
server = self._getNextServer()
|
||||||
|
socks_proxy = getattr(conf.supybot.networks, self.irc.network) \
|
||||||
|
.socksproxy()
|
||||||
|
resolver = None
|
||||||
|
try:
|
||||||
|
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:
|
try:
|
||||||
address = utils.net.getAddressFromHostname(server[0],
|
address = utils.net.getAddressFromHostname(server[0],
|
||||||
attempt=self._attempt)
|
attempt=self._attempt)
|
||||||
@ -276,15 +289,6 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
|||||||
return
|
return
|
||||||
drivers.log.connect(self.currentServer)
|
drivers.log.connect(self.currentServer)
|
||||||
try:
|
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)
|
self.conn = utils.net.getSocket(address, socks_proxy)
|
||||||
vhost = conf.supybot.protocols.irc.vhost()
|
vhost = conf.supybot.protocols.irc.vhost()
|
||||||
self.conn.bind((vhost, 0))
|
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
|
"""Returns a socket of the correct AF_INET type (v4 or v6) in order to
|
||||||
communicate with host.
|
communicate with host.
|
||||||
"""
|
"""
|
||||||
|
if not socks_proxy:
|
||||||
addrinfo = socket.getaddrinfo(host, None)
|
addrinfo = socket.getaddrinfo(host, None)
|
||||||
host = addrinfo[0][4][0]
|
host = addrinfo[0][4][0]
|
||||||
if socks_proxy:
|
if socks_proxy:
|
||||||
import socks
|
import socks
|
||||||
s = socks.socksocket()
|
s = socks.socksocket()
|
||||||
hostname, port = socks_proxy.rsplit(':', 1)
|
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
|
return s
|
||||||
if isIPV4(host):
|
if isIPV4(host):
|
||||||
return socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
return socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
Loading…
Reference in New Issue
Block a user