Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #A quick and dirty scanner for kali.
- #Download the code
- #Save it under the 'home' folder with Kali.
- #Open under terminal with <python3 scanner.py "ipaddress">
- #COPY THIS CODE:
- #!/bin/python3
- import sys #allows us to enter command line arguments among other things
- import socket
- from datetime import datetime
- from termcolor import colored
- #Define the target
- if len(sys.argv) == 2:
- target = socket.gethostbyname(sys.argv[1]) #Translates a host name to IPV4
- else:
- print("Invalid amount of arguments")
- print("Syntax: python3 scanner.py <ip>")
- sys.exit()
- #Add a banner
- print(colored("*" * 50, 'yellow'))
- print(colored("Scanning target " + target,'cyan', attrs=['blink']))
- print("Time Started " +str(datetime.now()))
- print (colored("Scanner created by Conan Bradley",'blue'))
- print(colored("*" * 50, 'yellow'))
- try:
- for port in range(50,85):
- #for every part in the range of 0-200
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- # INET= IPV$ and STREAM = port. We are defining a connection
- socket.setdefaulttimeout(1) # times out the port if no response in 1 second
- result = s.connect_ex((target,port)) #storing the result of the connection -returns error indicator if there is an error on the conection, if all is good, returns 0.Target is from declared variable above and port is declared in try block
- print("Checking Port {}".format(port))
- if result == 0:
- # We were successful in connecting
- print(colored("Port {} is open".format(port)))
- s.close()
- #closes connection
- except KeyboardInterrupt:
- print("\Exitiing Program")
- sys.exit()
- except socket.gaierror:
- print("Hostname could not be resolved.")
- sys.exit()
- except socket.error:
- print("Couldnt connect to server.")
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement