import xmpp import logging import socket import socks from xmpp import

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import xmpp
import logging
import socket
import socks
from xmpp import transports
PROXY = ''
PORT = 0
def custom_connect(self,server=None):
""" Try to connect. Returns non-empty string on success. """
try:
if not server: server=self._server
#self._sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
logging.debug('Using %s:%s SOCKS5 proxy' % (PROXY, PORT))
self._sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.setproxy(socks.PROXY_TYPE_SOCKS5, PROXY, PORT)
self._sock.connect(server)
self._send=self._sock.sendall
self._recv=self._sock.recv
self.DEBUG("Successfully connected to remote host %s"%`server`,'start')
return 'ok'
except socket.error, (errno, strerror):
self.DEBUG("Failed to connect to remote host %s: %s (%s)"%(`server`, strerror, errno),'error')
except Exception, ex:
logging.error(ex)
pass
transports.TCPsocket.connect = custom_connect