Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scapy.all as scapy
- import socket
- from getmac import get_mac_address as gma
- from mac_vendor_lookup import MacLookup
- import sys
- import threading
- from queue import Queue
- print_lock = threading.Lock()
- q = Queue()
- def mask_to_str(mask):
- z = list(map(int, mask.split(".")))
- return z[0] * (2 ** 24) + z[1] * (2 ** 16) + z[2] * (2 ** 8) + z[3]
- def mask_to_str1(ip):
- z = ip.to_bytes(4, 'big')
- return str(z[0]) + "." + str(z[1]) + "." + str(z[2]) + "." + str(z[3])
- def threader():
- while True:
- port = q.get()
- scanner(port)
- q.task_done()
- def scanner(port):
- #sys.stdout.write('{}\r'.format(port))
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- socket.setdefaulttimeout(0.0000001)
- global open_ports
- result = s.connect_ex((client_dict["ip"], port))
- if result == 0:
- #print("Port {} is open " .format(port))
- open_ports.append(port)
- print("-------------------------------------------------------------------------------------------------------")
- scapy.IFACES.show()
- print("-------------------------------------------------------------------------------------------------------")
- input_iface = input("Enter index of Network Interface: ")
- #input_ip = scapy.get_if_addr(scapy.IFACES.dev_from_index(input_iface))
- input_ip = input("Enter IP: ")
- input_mask = input("Enter Mask: ")
- print("-------------------------------------------------------------------------------------------------------")
- print("HOST NAME: ", socket.gethostname(), "\nHOST MAC: ", gma(), "\nHOST VENDOR: ", MacLookup().lookup(gma()))
- #print("IP of selected Network Interface: ", input_ip)
- print("-------------------------------------------------------------------------------------------------------")
- mask = mask_to_str(input_mask)
- for i in range(mask, 2 ** 32):
- ip = (mask & mask_to_str(input_ip)) + (i & (~mask))
- ipp = mask_to_str1(ip)
- print("Checking ", ipp)
- arp_req_frame = scapy.ARP(pdst = ipp)
- broadcast_ether_frame = scapy.Ether(dst = "ff:ff:ff:ff:ff:ff")
- broadcast_ether_arp_req_frame = broadcast_ether_frame / arp_req_frame
- answered_list = scapy.srp(broadcast_ether_arp_req_frame, timeout = 1, verbose = False, iface = scapy.IFACES.dev_from_index(input_iface))[0]
- result = []
- for i in range(0, len(answered_list)):
- client_dict = {"ip" : answered_list[i][1].psrc, "mac" : answered_list[i][1].hwsrc}
- print("-------------------------------------------------------------------------------------------------------")
- try:
- pip = client_dict["ip"]
- except:
- pip = "none"
- try:
- pmac = client_dict["mac"]
- except:
- pmac = "none"
- try:
- pname = socket.gethostbyaddr(ipp)[0]
- except:
- pname = "none"
- try:
- pvendor = MacLookup().lookup(pmac)
- except:
- pvendor = "none"
- print("IP: ", pip, " | MAC: ", pmac, " | NAME: ", pname, " | VENDOR: ", pvendor)
- global open_ports
- open_ports = []
- for x in range(100):
- thread = threading.Thread(target = threader)
- thread.daemon = True
- thread.start()
- for port in range(1, 65535):
- q.put(port)
- q.join()
- open_ports.sort()
- for i in range(0, len(open_ports)):
- print("Port {} is open" .format(open_ports[i]))
- print("-------------------------------------------------------------------------------------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement