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.
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()```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With