From d7e9a5df4efbfbd08bd8fdcd2e5808349a12259c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 13 Oct 2015 14:57:51 +0200 Subject: 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 --- oui-update.py | 14 +++++++++----- 1 file 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() -- cgit v1.2.3-54-g00ecf