![]() |
socket.timeout: timed out - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: socket.timeout: timed out (/thread-7136.html) |
socket.timeout: timed out - DanielGraham - Dec-22-2017 Hello everyone, I'm a newbie to Python programming and I've really fallen in love with the language; although I've got some little qualms right now. While reading the book "Violent Python A Cookbook for Hackers, Forensic Analysts, Penetration Testers and Security Engineers", I came across this piece of code: import socket socket.setdefaulttimeout(2) s = socket.socket() s.connect(("192.168.95.148",21)) ans = s.recv(1024) print ansWhen I typed it into the python console on Unix: I got this error message: So I carried out some research online for a solution or an explanation to what is going on. But I didn't find any that was convincing. For example, I were asked to modify that code to look like this: import socket try: s = socket.socket() s.settimeout(10) s.connect((192.168.95.148", 21)) ans = s.recv(1024) print ans s.shutdown(1) s.close() except socket.error as socketerror: print("Error: ", socketerror) except socket.timeout: print("NO RESPONSE")After running that one, I get this other error message: So, please if anyone could explain what this error messages actually mean and help me understand how I could fix that, I would be very grateful.
RE: socket.timeout: timed out - squenson - Dec-22-2017 The statement s.settimeout(10) sets a timeout period to 10 seconds. Then the statement s.connect(("192.168.95.148", 21)) tries to connect to the device which has the ip address 192.168.95.148 (this ip address is part of an internal network, not accessible from the Internet but only accessible within your internal network), on port 21. After 10 seconds, you will notice that the connection doesn't work, most probably because there is no device with such ip address on your internal network, so you get a timeout.
RE: socket.timeout: timed out - DanielGraham - Dec-22-2017 Alright, thanks a lot. Happy to know why it doesn't work.. I'm gonna try something else. |