I have a list of MAC addresses coming from a database. I would like to lookup the vendor for each MAC address and then have a count of devices on network by vendor in the end.

I believe I could do it the dirty way which would be to parse the vendor prefixes from the file available here http://standards.ieee.org/develop/regauth/oui/oui.txt.

But I'm wondering if there is a better way ?

有帮助吗?

解决方案

There is a library in Pear, but it does have substantial overhead involved in that the vendor lookup requires a relational database that's been loaded with the vendor data. However, considering the alternative this might be worth exploring.

http://pear.php.net/manual/en/package.networking.net-mac.php

The package provides a loader for the list maintained by wireshark: https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf

其他提示

If all you care about is getting the manufacturer of the device based on the mac address then you can simply copy and paste the list on this website here (unto 200 at a time). It's very quick:

www.admin-toolkit.com/mac-address-lookup-manufacturer.html

I have made an SQlite (Macvendors.db) from the Wireshark manuf source. I use it via PDO with a simple query.

Here is a method I write to show you how you could use it:

public function getAllCompaniesFromMacs($macs)
{
    try {
        // connect to the SQLite file
        $conn = new \PDO("sqlite:/path/to/sqlite/Macvendors.db");
        $conn ->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        // aux vars
        $macsParaBuscar = array();
        $macsIN = "";

        // output vars
        $salida = array();

        // Clean repeated MACs and remove the ":" chars
        foreach ($macs as $unaMac) {
            $unaMac = str_replace(":", "", $unaMac);
            $firstChars = substr($unaMac, 0, 6);
            $macsParaBuscar[$firstChars] = $firstChars;
        }

        // Create a IN statment for the WHERE
        $macsIN = "( 'HOLA'";
        foreach ($macsParaBuscar as $unaMacBuscar) {
            $macsIN .= ", '" . $unaMacBuscar . "'";
        }
        $macsIN .= ")"; 

        // Prepare and execute the query
        $stm = $conn->prepare("SELECT mac, vendor FROM macvendor WHERE mac IN " . $macsIN);
        $stm->execute();

        // Put results in output var
        while( $row = $stm->fetch() ) {
            $auxMac = $row["mac"];
            $salida[$auxMac] = $row["vendor"];
        }

        return $salida;

    } catch (\Exception $e) {

        throw new \Exception("Ha ocurrido un error", 1);

    }

}

Sorry about the unbeauty example code.

Have fun!

But I'm wondering if there is a better way ?

If you can use other languages like ruby, there's a gem called macvendors

There is no need to use an external api or get stopped by rate limit.

You can use it from your command line:

gem install macvendors macvendors find 98:e0:d9:a5:61:eb Apple, Inc.

You can use it in your ruby code:

require 'macvendors' MacVendors.setup #for the first time puts MacVendors.find("98:e0:d9:a5:61:eb")

Update

There is another library that doesn't depend on any API but the XML file database which is Cisco vendorMacs.xml

The package is hosted here


Yes here is one I wrote, it depends on the online API of Mac address vendor website

Here is the repository with examples

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top