Advertisement
CBra

Quick Scanner for Kali

Nov 12th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. #A quick and dirty scanner for kali.
  2. #Download the code
  3. #Save it under the 'home' folder with Kali.
  4. #Open under terminal with <python3 scanner.py "ipaddress">
  5.  
  6. #COPY THIS CODE:
  7.  
  8. #!/bin/python3
  9.  
  10. import sys #allows us to enter command line arguments among other things
  11. import socket
  12. from datetime import datetime
  13. from termcolor import colored
  14.  
  15. #Define the target
  16. if len(sys.argv) == 2:
  17.     target = socket.gethostbyname(sys.argv[1]) #Translates a host name to IPV4
  18. else:
  19.     print("Invalid amount of arguments")
  20.     print("Syntax: python3 scanner.py <ip>")
  21.     sys.exit()
  22.  
  23. #Add a banner
  24. print(colored("*" * 50, 'yellow'))
  25. print(colored("Scanning target " + target,'cyan', attrs=['blink']))
  26. print("Time Started " +str(datetime.now()))
  27. print (colored("Scanner created by Conan Bradley",'blue'))
  28. print(colored("*" * 50, 'yellow'))
  29.  
  30. try:
  31.     for port in range(50,85):
  32.         #for every part in the range of 0-200
  33.         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  34.         # INET= IPV$ and STREAM = port. We are defining a connection
  35.         socket.setdefaulttimeout(1) # times out the port if no response in 1 second
  36.         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
  37.         print("Checking Port {}".format(port))
  38.         if result == 0:
  39.         # We were successful in connecting
  40.             print(colored("Port {} is open".format(port)))
  41.         s.close()
  42.         #closes connection
  43.  
  44. except KeyboardInterrupt:
  45.     print("\Exitiing Program")
  46.     sys.exit()
  47.  
  48. except socket.gaierror:
  49.     print("Hostname could not be resolved.")
  50.     sys.exit()
  51.  
  52. except socket.error:
  53.     print("Couldnt connect to server.")
  54.     sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement