Sobre el scaner scanea por rangos y lista de puertos.
Código
#!/usr/bin/python2 import socket, sys, string if len(sys.argv)!=3 or sys.argv[1]=="-h": print "Escaner de puerto by Exe U.\n" print "Sintaxis> [HOST] [PUERTO/S]\n" print sys.argv[0] + " localhost 1-80" print sys.argv[0] + " localhost 21,22,23,25,110" print sys.argv[0] + " localhost 80" sys.exit() host = sys.argv[1] puertos = sys.argv[2] #Escaneo por rangos if string.find(puertos, "-") >= 1: puertos = puertos.split("-") for puerto in range(int(puertos[0]), int(puertos[1]) +1): try: sc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sc.connect((host,puerto)) print "Puerto %d" % puerto + " abierto" sc.close() except: pass #Escanea una lista de puertos elif string.find(puertos, ",") >= 1: puertos = puertos.split(",") for puerto in puertos: try: sc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sc.connect((host, int(puerto))) print "Puerto " + puerto + " abierto" sc.close() except: pass #Escanea un solo puerto elif puertos.isdigit(): try: sc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sc.connect((host, int(puertos))) print "Puerto " + puertos + " abierto" sc.close() except: pass
Salu2