Advertisement
MadCortez

Untitled

Jun 3rd, 2022
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.55 KB | None | 0 0
  1. import scapy.all as scapy
  2. import socket
  3. from getmac import get_mac_address as gma
  4. from mac_vendor_lookup import MacLookup
  5. import sys
  6. import threading
  7. from queue import Queue
  8.  
  9. print_lock = threading.Lock()
  10. q = Queue()
  11.  
  12. def mask_to_str(mask):
  13.     z = list(map(int, mask.split(".")))
  14.     return z[0] * (2 ** 24) + z[1] * (2 ** 16) + z[2] * (2 ** 8) + z[3]
  15.  
  16. def mask_to_str1(ip):
  17.     z = ip.to_bytes(4, 'big')
  18.     return str(z[0]) + "." + str(z[1]) + "." + str(z[2]) + "." + str(z[3])
  19.  
  20. def threader():
  21.     while True:
  22.         port = q.get()
  23.         scanner(port)
  24.         q.task_done()
  25.  
  26. def scanner(port):
  27.     #sys.stdout.write('{}\r'.format(port))
  28.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  29.     socket.setdefaulttimeout(0.0000001)
  30.     global open_ports
  31.  
  32.     result = s.connect_ex((client_dict["ip"], port))
  33.     if result == 0:
  34.         #print("Port {} is open  " .format(port))
  35.         open_ports.append(port)
  36.  
  37.  
  38. print("-------------------------------------------------------------------------------------------------------")
  39. scapy.IFACES.show()
  40. print("-------------------------------------------------------------------------------------------------------")
  41. input_iface = input("Enter index of Network Interface: ")
  42. #input_ip = scapy.get_if_addr(scapy.IFACES.dev_from_index(input_iface))
  43. input_ip = input("Enter IP: ")
  44. input_mask = input("Enter Mask: ")
  45. print("-------------------------------------------------------------------------------------------------------")
  46. print("HOST NAME: ", socket.gethostname(), "\nHOST MAC: ", gma(), "\nHOST VENDOR: ", MacLookup().lookup(gma()))
  47. #print("IP of selected Network Interface: ", input_ip)
  48. print("-------------------------------------------------------------------------------------------------------")
  49.  
  50. mask = mask_to_str(input_mask)
  51. for i in range(mask, 2 ** 32):
  52.     ip = (mask & mask_to_str(input_ip)) + (i & (~mask))
  53.     ipp = mask_to_str1(ip)
  54.     print("Checking ", ipp)
  55.     arp_req_frame = scapy.ARP(pdst = ipp)
  56.  
  57.     broadcast_ether_frame = scapy.Ether(dst = "ff:ff:ff:ff:ff:ff")
  58.        
  59.     broadcast_ether_arp_req_frame = broadcast_ether_frame / arp_req_frame
  60.  
  61.     answered_list = scapy.srp(broadcast_ether_arp_req_frame, timeout = 1, verbose = False, iface = scapy.IFACES.dev_from_index(input_iface))[0]
  62.     result = []
  63.     for i in range(0, len(answered_list)):
  64.         client_dict = {"ip" : answered_list[i][1].psrc, "mac" : answered_list[i][1].hwsrc}
  65.         print("-------------------------------------------------------------------------------------------------------")
  66.         try:
  67.             pip = client_dict["ip"]
  68.         except:
  69.             pip = "none"
  70.         try:
  71.             pmac = client_dict["mac"]
  72.         except:
  73.             pmac = "none"
  74.         try:
  75.             pname = socket.gethostbyaddr(ipp)[0]
  76.         except:
  77.             pname = "none"
  78.         try:
  79.             pvendor = MacLookup().lookup(pmac)
  80.         except:
  81.             pvendor = "none"
  82.         print("IP: ", pip, " | MAC: ", pmac, " | NAME: ", pname, " | VENDOR: ", pvendor)
  83.         global open_ports
  84.         open_ports = []
  85.         for x in range(100):
  86.             thread = threading.Thread(target = threader)
  87.             thread.daemon = True
  88.             thread.start()
  89.         for port in range(1, 65535):
  90.             q.put(port)
  91.         q.join()
  92.         open_ports.sort()
  93.         for i in range(0, len(open_ports)):
  94.             print("Port {} is open" .format(open_ports[i]))
  95.         print("-------------------------------------------------------------------------------------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement