Using normal sockets I can stream a list of numbers (updated every second) from a server to a client. This works perfectly fine. Now I want to do the same using Tor. Using Socksipy I am able to make HTTP requests to a web page (using this code). So from that starting point, I tried to build a piece of code that connects to a remote socket through Tor like this:
import socket import socks socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050, True) #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket = socks.socksocket s.connect(('<the ip address here>', 46956)) s.sendall('Hello world') print(s.recv(1024))
If I uncomment line 4 and comment out line 5 it all works fine, but running it like this results in an error saying:
TypeError: unbound method connect() must be called with socksocket instance as first argument (got tuple instance instead).
So my question: What am I doing wrong here? How can I connect to this remote socket through Tor?
Also two other questions:
- Is there no better way of doing this? By using
- How would I be able to build the public socket that I want to connect to, using a Tor hidden service?
Any information or hints are welcome.