Search the Community
Showing results for tags 'ftp-scanner'.
-
""" Port-/FTP-Scanner """ import socket import threading import sys import time import argparse def CheckIfOpen(ip,port): target = (ip,int(port)) try: socket.create_connection(target,1.5) open('open','a').write(ip+":"+str(port)+"\n") print("Port: "+str(port)+" open on IP: "+ip+"!\n") except: print("Port: "+str(port)+" closed on IP: "+ip+"!\n") def CheckIfPub(target): try: server = (target,21) user = "USER anonymous\r\n" pwd = "PASS anonymous\r\n" sock = socket.socket() sock.connect(server) sock.recv(4096) sock.sendall(user.encode()) if "331" in sock.recv(4096).decode('utf-8'): sock.sendall(pwd.encode()) answer = sock.recv(4096).decode('utf-8') if "230" in answer: open('found_ftp','a').write(target+":21 anonymous:anonymous\n") sock.recv(4096) sock.close() elif "530" in answer: sock.close() else: sock.close() except: print("Login failed!\n") pass parser = argparse.ArgumentParser() parser.add_argument("scan", type=str,choices=["ftp","port"],help="decide whether to scan for pubs or ports.") parser.add_argument("ranges",type=str,help="specify the file containing the ranges to scan, format: 123.123.123.123 123.123.123.123") parser.add_argument("-t","--threads",type=int,help="specify amount of threads, else the default will be 100.") parser.add_argument("-p","--ports",type=str,help="specify the port or ports to scan if you decided to scan for open ports. format: port1,port2,port3,...") args = parser.parse_args() if args.threads: threads = args.threads else: threads = 100 ranges = open(args.ranges).read().splitlines() for ipranges in ranges: chain = ipranges.split(" ") start = chain[0].split(".") end = chain[1].split(".") if int(end[3]) != 255: end[3] = int(end[3])+1 else: if int(end[2]) != 255: end[2] = int(end[2])+1 end[3] = 0 else: if int(end[1]) != 255: end[1] = int(end[1])+1 end[2] = 0 end[3] = 0 else: if int(end[0]) != 255: end[0] = int(end[0])+1 end[1] = 0 end[2] = 0 end[3] = 0 end = str(end[0])+"."+str(end[1])+"."+str(end[2])+"."+str(end[3]) current = str(start[0])+"."+str(start[1])+"."+str(start[2])+"."+str(start[3]) if args.scan == "port": try: ports = args.ports.split(",") except: ports = args.ports elif args.scan == "pub": ports = 21 while(current != end): for port in ports: if threading.active_count() <= threads: if args.scan == "port": T = threading.Thread(target=CheckIfOpen,args=(current,int(port),)) elif args.scan == "ftp": T = threading.Thread(target=CheckIfPub,args=(current,)) T.start() else: time.sleep(0.2) if args.scan == "port": T = threading.Thread(target=CheckIfOpen,args=(current,int(port),)) elif args.scan == "ftp": T = threading.Thread(target=CheckIfPub,args=(current,)) T.start() progress = current.split(".") if int(progress[3]) != 255: progress[3] = int(progress[3])+1 else: if int(progress[2]) != 255: progress[2] = int(progress[2])+1 progress[3] = 0 else: if int(end[1]) != 255: progress[1] = int(progress[1])+1 progress[2] = 0 progress[3] = 0 else: if int(progress[0]) != 255: progress[0] = int(progress[0])+1 progress[1] = 0 progress[2] = 0 progress[3] = 0 current = str(progress[0])+"."+str(progress[1])+"."+str(progress[2])+"."+str(progress[3]) open('current_ip','w').write(current) T.join() print("Scan finished!\n") exit()