-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.py
More file actions
executable file
·62 lines (52 loc) · 1.45 KB
/
Script.py
File metadata and controls
executable file
·62 lines (52 loc) · 1.45 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
56
57
58
59
60
61
62
import subprocess
import csv
import os
import sys
import urllib.request
import time
def cleanMac(mac):
retrn = ""
li = mac.split(":")
for i in li:
if len(i) <= 1:
var = "0" + i
retrn += var + ":"
else:
retrn += i + ":"
return retrn[:-1]
def manuFac(mac):
time.sleep(1)
req = urllib.request.Request('http://api.macvendors.com/' + mac)
try:
with urllib.request.urlopen(req) as response:
the_page = response.read()
return the_page
except:
return "Possible Error? or Unknown"
subprocess.run(["arp", "-a"], capture_output=True, text=True)
check = subprocess.run(["arp", "-a"], capture_output=True, text=True)
data = check.stdout.split("\n")
removeList = ["at", "on", "ifscope", "[ethernet]"]
final = []
with open(os.path.join(sys.path[0], "output.csv"), "w") as output:
writer = csv.writer(output)
for i in data:
item = i.split(" ")
if "(incomplete)" in item:
continue
for rem in removeList:
for it in item:
try:
item.remove(rem)
except ValueError:
pass
mac = item[2]
chkdMac = cleanMac(mac)
item[2] = chkdMac
manu = manuFac(chkdMac)
item.insert(0, manu)
if len(item) > 1:
final.append(item)
writer.writerow(item)
for i in final:
print(i)