Reputation: 73
I have made a very simple python script which should connect using the public ip of a device. However when running I get this error: OSError: [WinError 10051] A socket operation was attempted to an unreachable network
. I understand that this means my computer can't find a way to route to the ip, however I don't understand how to fix it.
Code:
import socket
ip = "some ip"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1", 5000))
s.connect((ip, 5000))
s.close()
Any help is appreciated.
Upvotes: 3
Views: 8977
Reputation: 73
Very simple fix, I just had to remove the bind and change the connect port to 80. Working code:
import socket
ip = "some ip"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Finding connection to target")
s.connect((ip, 80))
print("Connected to " + ip)
s.close()```
Upvotes: 3