-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac.py
40 lines (34 loc) · 1.17 KB
/
mac.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
import os, io, sys, time, json
class Mac:
def __init__(self):
self.loaded:bool = False
self.data:list = []
self.load()
def load(self):
try:
with open("data/mac.json", "r", encoding='utf8') as f:
self.data = json.load(f)
self.loaded = True
except OSError:
return
def search(self, mac:str="ff:ff:ff:ff:ff:ff"):
"""Search for the macadress prefix in the json
Args:
mac (str): Input MacAddress. Example: "ff:ff:ff:ff:ff:ff".
Returns:
dict: Dictionary with the result.
"""
# Wait until loaded
while not self.loaded: continue
# Search for the most complete macadress prefix
for i in range(3, len(mac)-4):
# Get the macadress prefix
query = str(mac[0:(len(mac)-i)]).upper()
# Skip useless invalid prefixes
if query[-1]==":": continue
# Compare the two prefixes
for line in self.data:
if query==line["macPrefix"]:
return line
# If not found, return None
return None