1

I'm working on a script that grabs the banner from common ports of a host. I'm using sockets to make the connection but I'm facing some issues. Here is the code:

    try:
    connsocket = socket(AF_INET, SOCK_STREAM)
    connsocket.settimeout( 5 )
    connsocket.connect((ip, port))
    connsocket.send("HEAD / HTTP/1.0")
    results = connsocket.recv(400)
    connsocket.close()
    return str(results)

except:
    print '[ERROR]Failed to connect or Connection timed out'

The are two major issues:

  • First time I run the script to a host all the banners are retrieved correctly except port 80 which exits with the timeout

  • The second problem is that when I relaunch the script to the same host there is no response from any port.

I suspect that the second issue is due to the connection is still open and the script fails retying to connect. With the first issue I have no idea why it's not working.

Any idea? Regards.

Nucklear
  • 478
  • 5
  • 21

0 Answers0