I'm having trouble with my code here, when I input a port range when it comes to a closed port the program will just pause. Its fine when it has open ports. Can anyone help?
#!/usr/bin/env python
import sys
import socket
import subprocess
address = raw_input("Which IP would you like to scan? ")
r1 = input("What starting IP would you like to scan? i.e 10: ")
r2 = input("Which ending IP would you like to scan? i.e 300: ")
print "This can take a while for big port ranges. Scan commencing on", address
for port in range(r1,r2):
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if(sock.connect_ex((address,port))==0):
print "Port " , port, "is open"
sock.close()
print " "
print "Scan completed sucessfully"
else:
print " "
print "Scan completed, No ports found!"