Coder Social home page Coder Social logo

mac_vendor_lookup's Introduction

Mac Vendor Lookup

This library provides an easy way to get vendor information from a MAC address. It contains a local copy of the IEEE's OUI prefix list. It has an asynchronous interface using Python 3's asyncio as well as a regular synchronous interface for old-school usage.

Installation

pip install mac-vendor-lookup

Basic Usage

from mac_vendor_lookup import MacLookup

print(MacLookup().lookup("00:80:41:12:FE"))

Output:

VEB KOMBINAT ROBOTRON

Update the vendor list

The library contains a list of MAC prefixes obtained at build-time. If you need up-to-date information, you can download a fresh copy of the list directly from IEEE with MacLookup.update_vendors or AsyncMacLookup.update_vendors:

from mac_vendor_lookup import MacLookup

mac = MacLookup()
mac.update_vendors()  # <- This can take a few seconds for the download
    
def find_mac(mac_address):
    print(mac.lookup(mac_address))

Vendor list custom location or path

The library stores and looks for the list of MAC prefixes in a group predefined defaults paths. If a custom directory is required, then override the class variable cache_path of class BaseMacLookup(...) from it default location of: os.path.expanduser('~/.cache/mac-vendors.txt') to your prefered location.

from mac_vendor_lookup import MacLookup, BaseMacLookup

BaseMacLookup.cache_path = "/relative/or/absolute/path/to/the/prefered/storage/location"
mac = MacLookup()
mac.update_vendors()  # <- This can take a few seconds for the download and it will be stored in the new path
    
def find_mac(mac_address):
    print(mac.lookup(mac_address))

Async Interface

There is also an asynchronous interface available:

from mac_vendor_lookup import AsyncMacLookup

async def main():
    mac = AsyncMacLookup()
    print(await mac.lookup("98:ED:5C:FF:EE:01"))

Output:

Tesla Motors, Inc

Command line interface

This library provides a rudimentary command line interface:

$ mac_vendor_lookup 50-D3-7F-00-01-00
Yu Fly Mikly Way Science and Technology Co., Ltd.
$ python3 -m mac_vendor_lookup 00:26:12:12:FE
Space Exploration Technologies

mac_vendor_lookup's People

Contributors

bauerj avatar msiegy avatar nsarfati avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mac_vendor_lookup's Issues

Unable to use library in Jupyter Notebook

Hello,

Please, can you help me?
When running the example from the readme (on Linux with Python3) I get this error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-35-21bff664f99d> in <module>
      1 from mac_vendor_lookup import MacLookup
      2 
----> 3 print(MacLookup().lookup("00:80:41:12:FE"))

~/.anaconda3/envs/nm/lib/python3.7/site-packages/mac_vendor_lookup.py in lookup(self, mac)
    108 
    109     def lookup(self, mac):
--> 110         return self.loop.run_until_complete(self.async_lookup.lookup(mac))
    111 
    112     def load_vendors(self):

~/.anaconda3/envs/nm/lib/python3.7/asyncio/base_events.py in run_until_complete(self, future)
    564         future.add_done_callback(_run_until_complete_cb)
    565         try:
--> 566             self.run_forever()
    567         except:
    568             if new_task and future.done() and not future.cancelled():

~/.anaconda3/envs/nm/lib/python3.7/asyncio/base_events.py in run_forever(self)
    519         self._check_closed()
    520         if self.is_running():
--> 521             raise RuntimeError('This event loop is already running')
    522         if events._get_running_loop() is not None:
    523             raise RuntimeError(

RuntimeError: This event loop is already running

Thanks in advance!

Add option to allow insecure SSL certificate during 'update_vendors()'

If you're behind a corporate proxy or other internet security device, downloading the latest client mac vendor DB may find unknown certificates in the lookup path...

from mac_vendor_lookup import MacLookup

obj = MacLookup()
obj.update_vendors()
oui_vendor = obj.lookup("aa:bb:cc:dd:ee:ff")

Running this yields...

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1007)

Please add an option to bypass ssl certificate checks during update_vendors()

Store list in path relative to calling script?

Hello, 1st of all excellent app, love how quick and simple to use it is.

Quick questions/request. Is there a way to store the mac-vendors.txt in a relative path to the python script calling the mac.update_vendors().

Folder Structure

web[folder]
  |
  |_______scripts[folder]
  |                   |_________my_script.py
  |
  |_______cache[folder]
                      |_________mac-address.py

my_script.py

mac = MacLookup()
mac.update_vendors()

address = '0000.1111.2222'
print(mac.lookup(address))

Thanks in advance

Does not work in Jupyter environment

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-4-82bea76dc231> in <module>
      1 mac = MacLookup()
----> 2 mac.update_vendors()
      3 
      4 #def find_mac(mac_address):
      5 #    print(mac.lookup(mac_address))

/opt/conda/lib/python3.7/site-packages/mac_vendor_lookup.py in update_vendors(self, url)
    105 
    106     def update_vendors(self, url=OUI_URL):
--> 107         return self.loop.run_until_complete(self.async_lookup.update_vendors(url))
    108 
    109     def lookup(self, mac):

/opt/conda/lib/python3.7/asyncio/base_events.py in run_until_complete(self, future)
    569         future.add_done_callback(_run_until_complete_cb)
    570         try:
--> 571             self.run_forever()
    572         except:
    573             if new_task and future.done() and not future.cancelled():

/opt/conda/lib/python3.7/asyncio/base_events.py in run_forever(self)
    524         self._check_closed()
    525         if self.is_running():
--> 526             raise RuntimeError('This event loop is already running')
    527         if events._get_running_loop() is not None:
    528             raise RuntimeError(

RuntimeError: This event loop is already running

Error while analyze mac

Good day!

Code:

vendor = MacLookup().lookup("B0:7B:25:C1:64:34")
print(vendor)

Result:

Traceback (most recent call last):
  File "./test-paramiko.py", line 56, in <module>
    vendor = MacLookup().lookup("B0:7B:25:C1:64:34")
  File "/usr/local/lib/python3.6/site-packages/mac_vendor_lookup.py", line 110, in lookup
    return self.loop.run_until_complete(self.async_lookup.lookup(mac))
  File "/usr/lib64/python3.6/asyncio/base_events.py", line 484, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.6/site-packages/mac_vendor_lookup.py", line 94, in lookup
    return self.prefixes[mac[:6]].decode("utf8")
KeyError: b'B07B25'

How fix this?

Command-line client install issue

The command-line version doesn't work by default because of a missconfiguration in setup.py

setup.py mentions:
entry_points={ # Optional 'console_scripts': [ 'mac_vendor_lookup=lookup:main', ], },

I believe instead of lookup:main it should be mac_vendor_lookup:main

PS: Thanks for the nice tool!

Downloading vendor list fails

Hi,

Using this for python3 in Microsoft Visual Studio, get this warning which (am not a Python expert) I do not understand. any ideas:

raceback (most recent call last):
File "F:\Derek\Source\Repos\WiFiProcessing\WiFiProcessing\WiFiProcessing.py", line 67, in
main()
File "F:\Derek\Source\Repos\WiFiProcessing\WiFiProcessing\WiFiProcessing.py", line 58, in main
find_mac("00:80:41:12:FE");
File "F:\Derek\Source\Repos\WiFiProcessing\WiFiProcessing\WiFiProcessing.py", line 9, in find_mac
print(mac.lookup(mac_address)) # <- this will only take a few µs!
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\mac_vendor_lookup.py", line 84, in lookup
return self.loop.run_until_complete(self.async_lookup.lookup(mac))
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\asyncio\base_events.py", line 468, in run_until_complete
return future.result()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\mac_vendor_lookup.py", line 72, in lookup
return self.prefixes[mac[:6]].decode("utf8")
KeyError: b'008041'
Press any key to continue . . .

KeyError for MAC with unregistered prefix

I'm receiving a KeyError when trying to resolve 56:26:9A:C2:54:D5

    return self.loop.run_until_complete(self.async_lookup.lookup(mac))
  File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
    return future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/home/pdcarney/.local/lib/python3.5/site-packages/mac_vendor_lookup.py", line 72, in lookup
    return self.prefixes[mac[:6]].decode("utf8")
KeyError: b'56269A'

Missing 0.1.12 tag and missing "sdist"

Hi.

It seems that the 0.1.12 tag is missing.

Additionally and probably more importantly though, can you do an sdist release on PyPi for this package? This would help greatly in packaging this tool up for RPM based distributions.

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.