Reputation: 1922
Does it possible to connect IRC via tor ?
Below my code for IRC server connection:
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect((self.server, self.port))
connection.send(
'USER {nickname} {nickname} {nickname} {nickname}\n'.format(nickname=self.nickname).encode('utf-8')
)
connection.send('NICK {nickname}\n'.format(nickname=self.nickname).encode('utf-8'))
Upvotes: 0
Views: 601
Reputation: 16184
connecting via SOCKS that Tor exposes is probably the easiest way.
the Python library PySocks works for me, install with the normal:
pip install -U PySocks
then do:
import socks
# assuming your Tor client is using the defaults
socks.set_default_proxy(socks.PROXY_TYPE_SOCKS5, 'localhost', 9150)
you can then make TCP connections as normal using the socks.socksocket
class, which will cause the actual connection to go via Tor
import socket
with socks.socksocket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('chat.freenode.net', 6667))
s.send('USER {0} {0} {0} {0}\r\n'.format(nickname).encode('utf8'))
s.send('NICK {0}\r\n'.format(nickname).encode('utf8'))
print(s.recv(4096).decode('utf8'))
Upvotes: 2