Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import subprocess
- import sys
- from datetime import datetime
- subprocess.call('cls', shell=True)
- print("Scan remote host? Y/N")
- getinput = input().lower()
- if getinput == "Y":
- remoteServer = input("Enter a remote host to scan: ")
- remoteServerIP = socket.gethostbyname(remoteServer)
- if getinput == "N":
- remoteServer = socket.gethostbyname(socket.gethostname())
- remoteServerIP = socket.gethostbyname(remoteServer)
- print("Would you like to automatic scan costum port range? Y/N")
- getinput = input().lower()
- if getinput == "Y":
- print("Please write which ports you would like to scan")
- costumrange = input().lower()
- try:
- for port in range(costumrange):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- result = sock.connect_ex((remoteServerIP, port))
- if result == 0:
- print ("Port {}: \t Open".format(port))
- sock.close()
- if getinput == "N":
- try:
- for port in range(1,1025):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- result = sock.connect_ex((remoteServerIP, port))
- if result == 0:
- print ("Port {}: \t Open".format(port))
- sock.close()
- print("-" * 76)
- print("Hold on, I'm scanning your ports! This might take a while. IP:", remoteServerIP)
- print("-" * 76)
- t1 = datetime.now()
- except socket.error:
- print ("Couldn't connect to server")
- sys.exit()
- t2 = datetime.now()
- total = t2 - t1
- print('Scan completed in: ', total)
- except socket.error:
- print ("Fejlbesked her...")
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment