-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #455 from pi-hole/new/network-details
Process ARP data for new network table
- Loading branch information
Showing
13 changed files
with
587 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,7 @@ version* | |
/pihole-FTL.conf | ||
/pihole-FTL.db | ||
/pihole-FTL.log | ||
|
||
# aux files | ||
aux/manuf.data | ||
aux/macvendor.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Pi-hole: A black hole for Internet advertisements | ||
# (c) 2019 Pi-hole, LLC (https://pi-hole.net) | ||
# Network-wide ad blocking via your own hardware. | ||
# | ||
# FTL Engine - auxiliary files | ||
# MAC -> Vendor database generator | ||
# | ||
# This is a python3 script | ||
# | ||
# This file is copyright under the latest version of the EUPL. | ||
# Please see LICENSE file for your rights under this license. | ||
|
||
import os | ||
import re | ||
import urllib.request | ||
import sqlite3 | ||
|
||
# Download raw data from Wireshark's website | ||
# We use the official URL recommended in the header of this file | ||
print("Downloading...") | ||
urllib.request.urlretrieve("https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf", "manuf.data") | ||
print("...done") | ||
|
||
# Read file into memory and process lines | ||
manuf = open("manuf.data", "r") | ||
data = [] | ||
print("Processing...") | ||
for line in manuf: | ||
line = line.strip() | ||
|
||
# Skip comments and empty lines | ||
if line[1] == "#" or line == "": | ||
continue | ||
|
||
# Remove quotation marks as these might interfere with later INSERT / UPDATE commands | ||
line = re.sub("\'|\"","", line) | ||
# \s = Unicode whitespace characters, including [ \t\n\r\f\v] | ||
cols = re.split("\s\s+|\t", line) | ||
# Use try/except chain to catch empty/incomplete lines without failing hard | ||
try: | ||
# Strip whitespace and quotation marks (some entries are incomplete and cause errors with the CSV parser otherwise) | ||
mac = cols[0].strip().strip("\"") | ||
except: | ||
continue | ||
try: | ||
desc_short = cols[1].strip().strip("\"") | ||
except: | ||
desc_short = "" | ||
try: | ||
desc_long = cols[2].strip().strip("\"") | ||
except: | ||
desc_long = "" | ||
|
||
# Only add long description where available | ||
# There are a few vendors for which only the | ||
# short description field is used | ||
if(desc_long): | ||
data.append([mac, desc_long]) | ||
else: | ||
data.append([mac, desc_short]) | ||
print("...done") | ||
manuf.close() | ||
|
||
# Create database | ||
database = "macvendor.db" | ||
|
||
# Try to delete old database file, pass if no old file exists | ||
try: | ||
os.remove(database) | ||
except OSError: | ||
pass | ||
|
||
print("Generating database...") | ||
con = sqlite3.connect(database) | ||
cur = con.cursor() | ||
cur.execute("CREATE TABLE macvendor (mac TEXT NOT NULL, vendor TEXT NOT NULL, PRIMARY KEY (mac))") | ||
cur.executemany("INSERT INTO macvendor (mac, vendor) VALUES (?, ?);", data) | ||
con.commit() | ||
print("...done.") | ||
print("Optimizing database...") | ||
con.execute("VACUUM") | ||
print("...done") | ||
print("Lines inserted into database:", cur.rowcount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.