Skip to content

Commit

Permalink
cleanup and bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberRoute committed Sep 24, 2024
1 parent f406f59 commit e8dd166
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions core/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def _load_from_file(cls, filename):
mac_vendor_data = []
next(csvreader) # Skip header row
for row in csvreader:
# Ensure the row has at least 4 elements (Registry, OUI, Organization Name, Organization Address)
if len(row) < 4:
continue

Expand Down Expand Up @@ -95,7 +94,6 @@ def _load_from_url(cls, url):
next(csvreader) # Skip header row
mac_vendor_data = []
for row in csvreader:
# Ensure the row has at least 4 elements (Registry, OUI, Organization Name, Organization Address)
if len(row) < 4:
continue

Expand All @@ -106,22 +104,22 @@ def _load_from_url(cls, url):
'Organization Address': row[3] # Organization address
})
return mac_vendor_data
else:
print(f"Failed to fetch data from {url}. Status code: {response.status_code}")
return []
print(f"Failed to fetch data from {url}. Status code: {response.status_code}")
return []



@classmethod
def _save_to_file(cls, filename, data):
"""Saves the MAC vendor data to a local CSV file.
The file will contain four columns: Registry, Assignment (OUI), Organization Name, and Organization Address.
The file will contain four columns:
Registry, Assignment (OUI), Organization Name, and Organization Address.
Args:
filename (str): The path to the file where the data should be saved.
data (list of dict): A list of dictionaries containing the fields:
'Registry', 'Assignment', 'Organization Name', and 'Organization Address'.
'Registry', 'Assignment', 'Organization Name', and 'Organization Address'.
"""
with open(filename, 'w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
Expand Down Expand Up @@ -156,8 +154,8 @@ def lookup_vendor(self, mac_address):
"""
cleaned_mac = mac_address.upper().replace(":", "").replace("-", "")
oui = cleaned_mac[:6]
for entry in self.mac_vendor_data:
if entry['Assignment'] == oui:
return entry['Organization Name'] # Return the organization name
if self.mac_vendor_data is not None:
for entry in self.mac_vendor_data:
if entry['Assignment'] == oui:
return entry['Organization Name'] # Return the organization name
return "Vendor not found"

0 comments on commit e8dd166

Please sign in to comment.