0

I have a script that I am currently writing to connect to a host via port 25. Once connected the following code is used to read a text file to gather each user and then issue the VRFY command along with the username. This works really well until I receive no response back from the host, it just hangs there. Towards the bottom of my code I have tried to break out if no response is received but this does not work. I have tried several ways to get it to work without any luck.

Thanks in advance!

with open('usernames.txt') as f:
    for users in f: 
        if users == '':
            break
        else:
            try:
                s.send('VRFY ' + users)
                result=s.recv(1024)
                print result
            except socket.timeout:
                print IPADDRESS + ' is not responding to VRFY commands'
                break
user826436
  • 231
  • 1
  • 4
  • 14
  • Is it a large amount of requests? Maybe the server is closing the connection because of a too huge amount of requests. I had a similar behavior with SSH servers (http://stackoverflow.com/questions/25609153/paramiko-error-reading-ssh-protocol-banner) In this case, try to sleep between requests / reach another server – FunkySayu Aug 19 '16 at 22:00
  • You can adjust the timeout? – Laurent LAPORTE Aug 19 '16 at 22:02
  • No at the moment I limited it down to one request. I think the server is set up to not respond to the request so I think I need to make it timeout. – user826436 Aug 19 '16 at 22:03
  • @LaurentLAPORTE How can I adjust the timeout? I have tried various things in my script in regards to timing out but I have had no luck. – user826436 Aug 19 '16 at 22:04
  • @user826436 the sockets module provides a [settimeout](https://docs.python.org/2/library/socket.html#socket.socket.settimeout) function.Did you try that? – FamousJameous Aug 19 '16 at 22:25

1 Answers1

0

Yes thank you, settimeout worked a treat! I used a excempt to catch it too. Thanks everyone!

user826436
  • 231
  • 1
  • 4
  • 14