SHOW:
|
|
- or go back to the newest paste.
| 1 | import socket | |
| 2 | import subprocess | |
| 3 | import sys | |
| 4 | from datetime import datetime | |
| 5 | ||
| 6 | subprocess.call('cls', shell=True)
| |
| 7 | print("Scan remote host? Y/N")
| |
| 8 | ||
| 9 | getinput = input().lower() | |
| 10 | if getinput == "Y": | |
| 11 | remoteServer = input("Enter a remote host to scan: ")
| |
| 12 | remoteServerIP = socket.gethostbyname(remoteServer) | |
| 13 | ||
| 14 | if getinput == "N": | |
| 15 | remoteServer = socket.gethostbyname(socket.gethostname()) | |
| 16 | remoteServerIP = socket.gethostbyname(remoteServer) | |
| 17 | ||
| 18 | print("Would you like to automatic scan costum port range? Y/N")
| |
| 19 | ||
| 20 | getinput = input().lower() | |
| 21 | ||
| 22 | if getinput == "Y": | |
| 23 | ||
| 24 | print("Please write which ports you would like to scan")
| |
| 25 | ||
| 26 | costumrange = input().lower() | |
| 27 | ||
| 28 | try: | |
| 29 | for port in range(costumrange): | |
| 30 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| 31 | result = sock.connect_ex((remoteServerIP, port)) | |
| 32 | if result == 0: | |
| 33 | print ("Port {}: \t Open".format(port))
| |
| 34 | sock.close() | |
| 35 | ||
| 36 | if getinput == "N": | |
| 37 | ||
| 38 | try: | |
| 39 | for port in range(1,1025): | |
| 40 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| 41 | result = sock.connect_ex((remoteServerIP, port)) | |
| 42 | if result == 0: | |
| 43 | print ("Port {}: \t Open".format(port))
| |
| 44 | sock.close() | |
| 45 | ||
| 46 | ||
| 47 | print("-" * 76)
| |
| 48 | print("Hold on, I'm scanning your ports! This might take a while. IP:", remoteServerIP)
| |
| 49 | print("-" * 76)
| |
| 50 | ||
| 51 | t1 = datetime.now() | |
| 52 | ||
| 53 | except socket.error: | |
| 54 | print ("Couldn't connect to server")
| |
| 55 | sys.exit() | |
| 56 | ||
| 57 | t2 = datetime.now() | |
| 58 | ||
| 59 | total = t2 - t1 | |
| 60 | ||
| 61 | - | print('Scan completed in: ', total) |
| 61 | + | print('Scan completed in: ', total) |