Skip to content

Instantly share code, notes, and snippets.

@ericpulvino
Created September 28, 2019 03:35
Show Gist options
  • Save ericpulvino/980d66206c69a44b69c1b47d89ba88ba to your computer and use it in GitHub Desktop.
Save ericpulvino/980d66206c69a44b69c1b47d89ba88ba to your computer and use it in GitHub Desktop.
Method to update the out of date MAC/OUI database in the python3 netaddr library
$ sudo pip3 install netaddr
[sudo] password for eric:
The directory '/home/eric/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/eric/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting netaddr
Downloading https://files.pythonhosted.org/packages/ba/97/ce14451a9fd7bdb5a397abf99b24a1a6bb7a1a440b019bebd2e9a0dbec74/netaddr-0.7.19-py2.py3-none-any.whl (1.6MB)
100% |████████████████████████████████| 1.6MB 978kB/s
Installing collected packages: netaddr
Successfully installed netaddr-0.7.19
[23:24] eric @ p52: ~
$ python3
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import netaddr as na
>>> import re
>>> _mac = '88-E9-FE-1F-65-7D'
>>> if re.match('[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$', _mac.lower()):
... print(f'{_mac} - {na.EUI(_mac).oui.registration().org}')
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/local/lib/python3.6/dist-packages/netaddr/eui/__init__.py", line 478, in oui
return OUI(self.value >> 24)
File "/usr/local/lib/python3.6/dist-packages/netaddr/eui/__init__.py", line 101, in __init__
raise NotRegisteredError('OUI %r not registered!' % oui)
netaddr.core.NotRegisteredError: OUI 8972798 not registered!
>>> ctrl+d
[23:24] eric @ p52: ~
$ python3
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import netaddr
>>> netaddr.__file__
'/usr/local/lib/python3.6/dist-packages/netaddr/__init__.py'
>>> ctrl+d
[23:28] eric @ p52: ~
$ cd /usr/local/lib/python3.6/dist-packages/netaddr
[23:28] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr
$ ls
compat.py contrib core.py eui fbsocket.py __init__.py ip __pycache__ strategy
[23:28] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr
$ cd ./eui
[23:28] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ ls -lha
total 6.3M
drwxr-sr-x 3 root staff 4.0K Sep 27 23:24 .
drwxr-sr-x 7 root staff 4.0K Sep 27 23:24 ..
-rw-r--r-- 1 root staff 94K Sep 27 23:24 iab.idx
-rw-r--r-- 1 root staff 2.4M Sep 27 23:24 iab.txt
-rw-r--r-- 1 root staff 9.3K Sep 27 23:24 ieee.py
-rw-r--r-- 1 root staff 25K Sep 27 23:24 __init__.py
-rw-r--r-- 1 root staff 410K Sep 27 23:24 oui.idx
-rw-r--r-- 1 root staff 3.5M Sep 27 23:24 oui.txt
drwxr-sr-x 2 root staff 4.0K Sep 27 23:24 __pycache__
[23:28] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ sudo mv ./oui.txt ./oui.txt.backup
[23:28] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ sudo wget http://standards-oui.ieee.org/oui.txt
--2019-09-27 23:29:04-- http://standards-oui.ieee.org/oui.txt
Resolving standards-oui.ieee.org (standards-oui.ieee.org)... 140.98.223.27
Connecting to standards-oui.ieee.org (standards-oui.ieee.org)|140.98.223.27|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4255622 (4.1M) [text/plain]
Saving to: ‘oui.txt’
oui.txt 100%[==============================================>] 4.06M 1.32MB/s in 3.1s
2019-09-27 23:29:08 (1.32 MB/s) - ‘oui.txt’ saved [4255622/4255622]
[23:29] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ ls
iab.idx iab.txt ieee.py __init__.py oui.idx oui.txt oui.txt.backup __pycache__
[23:29] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ sudo mv ./oui.idx ./oui.idx.backup
[23:29] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ ls
iab.idx iab.txt ieee.py __init__.py oui.idx.backup oui.txt oui.txt.backup __pycache__
[23:29] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ sudo ./ieee.py
sudo: ./ieee.py: command not found
Exit status: 1 [23:29] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ sudo python3 ./ieee.py
[23:29] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ ls
iab.idx iab.txt ieee.py __init__.py oui.idx oui.idx.backup oui.txt oui.txt.backup __pycache__
[23:29] eric @ p52: /usr/local/lib/python3.6/dist-packages/netaddr/eui
$ python3
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import netaddr as na
>>> import re
>>>
>>> _mac = '88-E9-FE-1F-65-7D'
>>> if re.match('[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$', _mac.lower()):
... print(f'{_mac} - {na.EUI(_mac).oui.registration().org}')
...
88-E9-FE-1F-65-7D - Apple, Inc.
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment