summaryrefslogtreecommitdiff
path: root/oui-update.py
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-10-13 14:57:51 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-10-13 14:57:51 +0200
commitd7e9a5df4efbfbd08bd8fdcd2e5808349a12259c (patch)
treefacb426787cfba702340114fdfe93db0064a2899 /oui-update.py
parent19c15748cb0eb431ef20f32ff629a82a6c2b3635 (diff)
oui-update: Explicitly sort OUI list and strip trailing whitespaces
It looks like http://standards-oui.ieee.org/oui.txt is no longer sorted by OUI, so do in manually when creating oui.conf. Also, it looks like the file has been converted to use CRLF line endings, so strip those as well (and any other trailing whitespaces in the vendor name). Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'oui-update.py')
-rwxr-xr-xoui-update.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/oui-update.py b/oui-update.py
index f9e588e..07add9f 100755
--- a/oui-update.py
+++ b/oui-update.py
@@ -62,20 +62,24 @@ def main():
print("Updating OUI information in {} from {}... ".format(output_file, oui_url))
- fh_file = open(output_file, 'w')
fh_url = urlopen(oui_url)
- n = 0
+ ouis = []
for line in fh_url:
m = OUI_PATTERN.match(line)
if m:
- fh_file.write("0x{}{}{}, {}\n".format(m.group(1), m.group(2), m.group(3), m.group(4)))
- n += 1
+ oui = "0x{}{}{}".format(m.group(1), m.group(2), m.group(3))
+ vendor = m.group(4).rstrip()
+ ouis.append((oui, vendor))
- print("{} OUIs written to {}".format(n, output_file))
+ fh_file = open(output_file, 'w')
+ for oui, vendor in sorted(ouis):
+ fh_file.write("{}, {}\n".format(oui, vendor))
fh_url.close()
fh_file.close()
+ print("{} OUIs written to {}".format(len(ouis), output_file))
+
if __name__ == '__main__':
main()