Repository navigation
Expand file tree
/
Copy pathnetwork_scanner.py
More file actions
55 lines (43 loc) · 1.53 KB
/
Copy pathnetwork_scanner.py
File metadata and controls
55 lines (43 loc) · 1.53 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# network scanner using ARP request
# paired with a list of known MAC from companies
import optparse
import socket
from scapy.all import *
def opt_parse():
parser = optparse.OptionParser()
parser.add_option("-i", "--ipaddr", dest="ipaddr", help="Address IP of the network")
return parser.parse_args()
def find_device_company(MAC):
a,b,c,d,e,f = MAC.split(":")
mac = a+b+c
try:
file = open("test_files/mac-vendor.txt", "r")
for line in file:
if mac.upper() in line:
company = line[7:].strip("\n")
return company
except:
pass
def scan(ip):
arp_request = scapy.all.ARP(pdst=ip)
broadcast = scapy.all.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_req_broad = broadcast / arp_request
answered_list = scapy.all.srp(arp_req_broad, timeout=1, verbose=False)[0]
print("IP\t\t\tMAC Address\t\tHostname\t\tCompany\n----------------------------------------------------------------------------------")
for element in answered_list:
mac_addr = str(element[1].hwsrc)
ip_addr = str(element[1].psrc)
try:
dns = socket.gethostbyaddr(ip_addr)
hostname = dns[0]
except:
pass
print element[1].psrc + "\t\t" + element[1].hwsrc +"\t",
try:
print str(hostname)[0:16] + "\t\t",
except:
print "NOT FOUND" + "\t\t",
print str(find_device_company(mac_addr))[0:20]
(options, arguments) = opt_parse()
scan(options.ipaddr)