diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2018-12-10 15:10:23 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2018-12-10 15:10:23 +0100 |
commit | 777e92c96a85f499ec272c0d130c631e5bf6362a (patch) | |
tree | f8f0b7fcc8df6f252b603c63c18740fc1211fd77 /contrib | |
parent | 79608cdc169b5da7ddcfa70fd5faf1e1e399d2f7 (diff) |
oui.conf: update from upstream
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/oui-update.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/contrib/oui-update.py b/contrib/oui-update.py index 07add9f..3e4ddde 100755 --- a/contrib/oui-update.py +++ b/contrib/oui-update.py @@ -14,14 +14,14 @@ import sys import re import getopt try: - from urllib2 import urlopen # Python 2.x -except ImportError: - from urllib.request import urlopen # Python 3.x + from urllib.request import urlopen +except ImportError as e: + raise Exception("Please run this script with Python 3") DEFAULT_OUPUT_FILE = "oui.conf" DEFAULT_OUI_URL = "http://standards.ieee.org/develop/regauth/oui/oui.txt" -OUI_PATTERN = re.compile(b"^\s*([a-fA-F0-9]{2})-([a-fA-F0-9]{2})-([a-fA-F0-9]{2})\s+\(hex\)\s+(.*)$") +OUI_PATTERN = re.compile("^\s*([a-fA-F0-9]{6})\s+\(base 16\)\s+(.*)$") def usage(): print("""usage: {0} [OPTION...] @@ -63,13 +63,16 @@ def main(): print("Updating OUI information in {} from {}... ".format(output_file, oui_url)) fh_url = urlopen(oui_url) + encoding = fh_url.headers.get_content_charset() + if not encoding: + encoding = "utf-8" ouis = [] for line in fh_url: - m = OUI_PATTERN.match(line) + m = OUI_PATTERN.match(line.decode(encoding)) if m: - oui = "0x{}{}{}".format(m.group(1), m.group(2), m.group(3)) - vendor = m.group(4).rstrip() + oui = "0x{}".format(m.group(1)) + vendor = m.group(2).rstrip() ouis.append((oui, vendor)) fh_file = open(output_file, 'w') |