-
Notifications
You must be signed in to change notification settings - Fork 0
/
Device_Scanner.py
executable file
·41 lines (29 loc) · 1.27 KB
/
Device_Scanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import scapy.all as scapy
def scan(ip):
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast / arp_request
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
clients_list= []
for element in answered_list:
client_dict ={"ip": element[1].psrc, "mac": element[1].hwsrc}
clients_list.append(client_dict)
print_result(clients_list)
#return clients_list
def vendor(mac_original):
mac_new = mac_original.replace(":", "").upper()
with open ("vendor.txt") as f:
for entry in f.readlines():
prefix, vendor = entry.split("\t")[0], entry.split("\t")[1].strip()
if mac_new.startswith(prefix):
return vendor
def print_result(results_list):
print("----------------------------------------------------------------------")
print("IP\t\t\tMAC Address\t\t\tVENDOR\n----------------------------------------------------------------------")
for client in results_list:
vname = str(vendor(client['mac']))
if vname == "None":
vname = "Unknown"
print(f"{client['ip']}\t\t{client['mac']}\t\t{vname}")
scan('192.168.1.1/24')