diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-03-15 10:41:48 +0100 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-03-15 10:41:48 +0100 |
commit | 1a9fbac03c684f29cff9ac44875bd9504a89f54e (patch) | |
tree | 1b2e40dbe5dc1899ef5b62c4325c9b94c9c450fc /update-oui.py |
all: import netsniff-ng 0.5.8-rc0 source
We decided to get rid of the old Git history and start a new one for
several reasons:
*) Allow / enforce only high-quality commits (which was not the case
for many commits in the history), have a policy that is more close
to the one from the Linux kernel. With high quality commits, we
mean code that is logically split into commits and commit messages
that are signed-off and have a proper subject and message body.
We do not allow automatic Github merges anymore, since they are
total bullshit. However, we will either cherry-pick your patches
or pull them manually.
*) The old archive was about ~27MB for no particular good reason.
This basically derived from the bad decision that also some PDF
files where stored there. From this moment onwards, no binary
objects are allowed to be stored in this repository anymore.
The old archive is not wiped away from the Internet. You will still
be able to find it, e.g. on git.cryptoism.org etc.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'update-oui.py')
-rwxr-xr-x | update-oui.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/update-oui.py b/update-oui.py new file mode 100755 index 0000000..52af122 --- /dev/null +++ b/update-oui.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# update-oui.py -- update netsniff-ng oui.conf from official IEEE OUI list +# +# Copyright (C) 2013 Tobias Klauser <tklauser@distanz.ch> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +import os +import sys +import re +import getopt +try: + from urllib2 import urlopen # Python 2.x +except ImportError: + from urllib.request import urlopen # Python 3.x + +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+(.*)$") + +def usage(): + print("""usage: {0} [OPTION...] +available options: + -f force overwrite of existing file + -o set output file (default: {1}) + -u set URL to fetch OUI list from (default: {2}) + -h show this help and exit""".format(os.path.basename(sys.argv[0]), + DEFAULT_OUPUT_FILE, DEFAULT_OUI_URL)) + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "fo:u:h") + except getopt.GetoptError as err: + print(str(err)) + usage() + sys.exit(-1) + + overwrite = False + output_file = DEFAULT_OUPUT_FILE + oui_url = DEFAULT_OUI_URL + for o, a in opts: + if o == '-f': + overwrite = True + elif o == '-o': + output_file = a + elif o == '-u': + oui_url = a + elif o == '-h': + usage() + sys.exit(0) + else: + assert False, "unhandled option" + + if not overwrite and os.path.exists(output_file): + print("Eror: output file {} already exists".format(output_file)) + sys.exit(-1) + + print("Updating OUI information in {} from {}... ".format(output_file, oui_url)) + + fh_file = open(output_file, 'w') + fh_url = urlopen(oui_url) + + n = 0 + 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 + + print("{} OUIs written to {}".format(n, output_file)) + + fh_url.close() + fh_file.close() + +if __name__ == '__main__': + main() |