Dec-22-2017, 02:12 PM
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:Error:Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.timeout: timed outSo 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:Error:('Error: ', timeout('timed out',))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.
