Skip to content

Instantly share code, notes, and snippets.

@franquis
Created October 18, 2013 08:45
Show Gist options
  • Save franquis/7038535 to your computer and use it in GitHub Desktop.
Save franquis/7038535 to your computer and use it in GitHub Desktop.
Parsing IEEE OUI with Python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import urllib2, re
def ParseIEEEOui(url = "http://standards.ieee.org/develop/regauth/oui/oui.txt"):
req = urllib2.Request(url)
res = urllib2.urlopen(req)
data = res.read()
IEEOUI = []
for line in data.split('\n'):
try:
mac, company = re.search(r'([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2})\s+\(hex\)\s+(.+)', line).groups()
IEEOUI.append(dict(mac=mac, company=company))
except AttributeError:
continue
return IEEOUI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment