├── README.md └── scanner_port (1).py /README.md: -------------------------------------------------------------------------------- 1 | Port_Scanner 2 | Complet and easy to run Port Scanner with Python 3 | 4 | Installation 5 | 1- git clone https://github.com/s120000/Port_Scanner 2- cd Port_Scanner 3- python3 scanner_port.py 6 | 7 | Requeriments 8 | 1- socket (pip3 install sockets) 2- pyfiglet (pip3 install pyfiglet) 3- datetime (pip3 install datetime) 4- sys (pip3 install os-sys) 5- nmap (pip3 install python-nmap) 9 | 10 | #Usage python3 scanner_port.py 11 | -------------------------------------------------------------------------------- /scanner_port (1).py: -------------------------------------------------------------------------------- 1 | import socket 2 | import pyfiglet 3 | from datetime import datetime 4 | import sys 5 | import nmap 6 | from getmac import get_mac_address 7 | 8 | banner = pyfiglet.figlet_format("Port Scanner") 9 | print(banner) 10 | 11 | linea = ("-------------------------------------------------------") 12 | linea2 = ("-------------------------------------------------------") 13 | 14 | hora = datetime.now() 15 | 16 | socket1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 17 | escoje = int(input("Choose option \n 1- See status of one port \n 2- See status of all ports \n 3- See status of range \n 4- Host Discovery \n Option: ")) 18 | host = input("Which host do you want to scan?\n Host: ") 19 | all_ports = 1 20 | 21 | def service(port): 22 | serv = socket.getservbyport(port) 23 | print(serv) 24 | 25 | 26 | def un_puerto(port): 27 | port2 = 43 28 | print(linea) 29 | print(linea) 30 | print("Starting Scan...", hora) 31 | print(linea) 32 | print(linea,"\n") 33 | 34 | if socket1.connect_ex((host,port)): 35 | print("Closed") 36 | else: 37 | print("The Port", port, "are Opened") 38 | print("The service working are") 39 | service(port) 40 | 41 | def todos(all_ports): 42 | try: 43 | for port in range(1,65535): 44 | socket2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 45 | connection = socket2.connect_ex((host, port)) 46 | if connection == 0: 47 | serv = socket.getservbyport(port) 48 | print("Port", port, "are Opened \t", serv, "service working") 49 | socket2.close() 50 | 51 | except KeyboardInterrupt: 52 | print ("You pressed Ctrl+C") 53 | sys.exit() 54 | 55 | def rango(): 56 | try: 57 | for port in range(a,b): 58 | socket4 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 59 | connection = socket4.connect_ex((host, port)) 60 | if connection == 0: 61 | serv = socket.getservbyport(port) 62 | print("Port", port, "are Opened \t", serv, "service working") 63 | socket4.close() 64 | 65 | except KeyboardInterrupt: 66 | print ("You pressed Ctrl+C") 67 | sys.exit() 68 | 69 | 70 | def mac(IP="idk"): 71 | mac2 = get_mac_address(ip=IP) 72 | print(mac2) 73 | 74 | def host_discover(): 75 | a = nmap.PortScanner() 76 | print(linea2) 77 | print("Starting Scan...",hora) 78 | print(linea2) 79 | a.scan(hosts=hosts1, arguments="-sn") 80 | lista_hosts = [(x, a[x] ["status"]["state"]) for x in a.all_hosts()] 81 | print("Active hosts: \t Status: \n") 82 | for host, status in lista_hosts: 83 | print("MAC:") 84 | print("IP:\n",host,"\t ", status," ",mac(host),"\n") 85 | 86 | if escoje == 1: 87 | port = int(input("What port do you want to see the status of? \n Port: ")) 88 | un_puerto(port) 89 | elif escoje == 2: 90 | todos(all_ports) 91 | elif escoje == 3: 92 | a = int(input("First number of range: ")) 93 | b = int(input("Second number of range: ")) 94 | rango() 95 | elif escoje == 4: 96 | hosts1 = input("Your subnet (with CIDR x.x.x.x/CIDR) \n Subnet: ") 97 | host_discover() 98 | else: 99 | print("Invalid option") 100 | 101 | 102 | --------------------------------------------------------------------------------