I am making a Python program with what I learned so far where the user enters two IPs that represents the start and end of the range of IPs to be scanned, then saves the wanted IP in a text file.   #ip range and scanningimport socketimport sysok=[]def ipscan(start2,port):    s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)    s.settimeout(2)    try:        s.connect((start2,port))        print start2 ,'-->port %s is Open'%port        ok.append(start2)    except: print start2 ,'-->port %s is Closed ! '%portdef iprange(start,end):    while end>start:       start[3]+=1       ipscan('.'.join(map(str,start)),p)       for i in (3,2,1,0):          if start[i]==255:             start[i-1]+=1             start[i]=0 #--------------------------------------------#    sta=map(int,raw_input('From : ').split('.'))fin=map(int,raw_input('to : ').split('.'))p=input('Port to scan : ')iprange(sta,fin)print '-----------end--------------'of=open('Output.txt','w')for ip in ok:    of.writelines(ip+'\n')of.close()It seems to be working but I need to be sure, and wanted to know if I can make it any faster, or if there is a better way.
Port-scanning with two IPs
python;socket