findVendor()

findVendor() – Finds the vendor of the MAC address stored in the object

Synopsis

require_once 'Net/MAC.php';

mixed findVendor ( string $getDescription = false , string $macList = null )

Description

This method will search through the database to find a vendor that matches the MAC address stored in the class using setMac(). If the $macList parameter is set, the method will use the array stored in $macList as the data source to find the MAC vendor instead of the database. The array would have to be an array with the same characteristics as one returned from the importVendors() method when using the $doReturn parameter.

Parameter

  • string $getDescription - If set to TRUE, the return value will be an array with keys 'vendor' and 'description'. Normally the method will simply return the vendor name.

  • string $macList - An optional list of MAC-to-vendor relationships to search instead of using the database.

Return value

mixed - Returns an associative array if $getDescription is TRUE, returns a string with the vendor name if $getDescription is FALSE. If the MAC vendor cannot be found in the vendor list, FALSE is returned.

Note

This function can not be called statically.

Example

Using findVendor()

<?php
require_once 'Net/MAC.php';
require_once 
'MDB2.php';

$db_type 'pgsql';
$db_host 'localhost';
$db_user 'username';
$db_name 'dbname';
$db_pass 'password';

$dsn "$db_type://$db_user:$db_pass@$db_host/$db_name";

$dbh =& MDB2::factory($dsn);

if (
MDB2::isError($dbh)) {
  echo 
"MDB2 Error: ".$dbh->getUserInfo();
}

$dboptions = array('tablename' => 'macvendors',
           
'macaddrcol' => 'macaddr',
           
'vendorcol' => 'vendor',
           
'desccol' => 'description');

try {
  
$nmh =& new Net_MAC($dbh$dboptions);
} catch (
Net_MAC_Exception $e) {
  echo 
'Net_MAC Error: ' $e->getMessage();
  exit;
}

$nmh->setMAC('00:11:22:33:44:55');
$result $nmh->findVendor(true);
if (
is_array($result)) {
  foreach(
$result as $key => $value) {
    echo 
"$key$value<br>\n";
  }
}
else {
  echo 
$result;
}
?>

This would output the following:

vendor: Cimsys
description: CIMSYS Inc