Commits

buge  committed 14d4bac

Added quick support for OUI recognition.

  • Participants
  • Parent commits 291292c

Comments (0)

Files changed (2)

 
 import operator
 
+try:
+    from oui import OUIS
+except ImportError:
+    OUIS = {}
+
 
 __all__ = [
     'Address',
         from uuid import getnode
         return EUI48Address(getnode())
 
+    def get_oui_number(self):
+        return self.get_address() >> (self.__class__.BIT_SIZE - 24)
+
+    def get_oui_name(self):
+        return OUIS.get(self.get_oui_number())
+
     def as_eui48(self):
         return NotImplementedError("abstract method")
 
+#!/usr/bin/env python
+
+import codecs
+
+input = codecs.open('oui.txt', 'r', 'latin-1', errors='replace')
+
+output = open('oui.py', 'w')
+output.write("""# Copyright (C) 2011  Philipp Bunge
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+__all__ = [ 'OUIS' ] 
+
+OUIS = {
+""")
+
+#   awk '
+#   BEGIN {
+#       FS="[-\t ]"
+#       print "OUIS = {"
+#   }
+
+#   /(hex)/ {
+#       hex = $1 $2 $3
+#       name = substr($0, 19)
+#       printf("    0x%s: \"%s\",\n", hex, name) 
+#   }
+
+#   END {
+#       print "}"
+#       print
+#   }
+#   ' < oui.txt >> oui.py
+
+
+for l in input:
+    if not "(hex)" in l:
+        continue
+    output.write("    0x%s%s%s: %r,\n" % (l[0:2], l[3:5], l[6:8], l[18:-1]))
+
+output.write("}\n\n")
+
+input.close()
+output.close()
+