Net_MAC
[ class tree: Net_MAC ] [ index: Net_MAC ] [ all elements ]

Class: Net_MAC

Source Location: /Net_MAC-0.1.5/Net/MAC.php

Class Overview


Class to validate and cleanly format Media Access Control (MAC) addresses


Author(s):

Version:

  • 1.0

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 87]
Class to validate and cleanly format Media Access Control (MAC) addresses


[ Top ]


Class Variables

$_db =

[line 104]

A database instance to use in looking up MAC-to-vendor relationships.
  • Access: protected

Type:   object


[ Top ]

$_dbOptions =

[line 112]

The options to use while connecting to the database.
  • Access: protected

Type:   array


[ Top ]

$_macaddr =

[line 95]

The MAC address to work on.
  • Access: protected

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 146]

void __construct( object &$db, [array $options = NULL])

The default constructor

This is the default constructor that will create and populate a valid Net_MAC object.

  • Return: No return value. A Net_MAC_Exception Exception object will be thrown if there is an error during construction so the constructor should be called from a try/catch block
  • Access: public

Parameters:

object   &$db   —  A valid instantiated MDB2 object to use when adding/retrieving information from the database for MAC address vendors
array   $options   — 

An array of options to use with the database in retrieving MAC address vendors. The associative array should have key/value pairs as follows:

  • tablename: The name of the table where MAC address vendor information lives
  • macaddrcol: The name of the column containing the MAC address prefixes
  • vendorcol: The name of the column containing the vendor name
  • desccol: The name of the column containing any extra descriptive information derived from the vendor list


[ Top ]

check   [line 197]

string check( string $input, [string $delimiter = ':'])

Checks a MAC address

This function will check a MAC address to make sure it is valid.

  • Return: true if the MAC address is valid, false otherwise

Parameters:

string   $input   —  The string containing the MAC Address
string   $delimiter   —  The string representing the delimiter to use when verifying the MAC Address

[ Top ]

findVendor   [line 391]

mixed findVendor( [bool $getDescription = false], [array $macList = NULL])

Finds the vendor for a MAC address

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.

  • Return: 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.
  • Access: public

Parameters:

bool   $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.
array   $macList   —  An optional list of MAC-to-vendor relationships to search instead of using the database. (default: NULL)

[ Top ]

format   [line 252]

string format( string $input, [string $delimiter = ':'], [bool $uppercase = true])

Formats a MAC address

This function will format a MAC address into XX:XX:XX:XX:XX:XX format from whatever format is passed to the function. The delimiter (: in the example above) will be replaced with whatever string is passed to the $delimiter parameter (default :).

  • Return: The formatted MAC Address or false on error

Parameters:

string   $input   —  The string containing the MAC Address
string   $delimiter   —  The string representing the delimiter to use when formatting the MAC Address
bool   $uppercase   —  If set to true (default), the hexadecimal values in the MAC Address will be returned in uppercase. If false, the hexadecimal values will be returned in lowercase.

[ Top ]

importVendors   [line 307]

mixed importVendors( string $file, [bool $doReturn = false])

Import a manufacturers' file to the database

This method will parse a manufacturers' file, such as the one from http://anonsvn.wireshark.org/wireshark/trunk/manuf, containing a list of MAC address prefix-to-vendor relationships. If the $doReturn parameter is false, then the data will be imported into the database defined by the factory of this class. However, if $doReturn is true, then the return will be an associative array with the key being the MAC address prefix and the data being an associative array with the keys 'vendor' and 'description'.

  • Return: If $doReturn is true, the method will return an array. Otherwise, the method will return true on success. A Net_MAC_Exception Exception object will be thrown on failure in either case.
  • Access: public

Parameters:

string   $file   —  The filename or URL of the manufacturers' file to parse.
bool   $doReturn   —  If true, an array will be returned, if false, the data will be imported into the database. (default: false)

[ Top ]

setMAC   [line 219]

bool setMAC( string $macaddr, [string $delimiter = ':'])

Sets the MAC address

This method will set the MAC address in the class.

  • Return: Returns true if the MAC address is set correctly, false otherwise
  • Access: public

Parameters:

string   $macaddr   —  The string representing the MAC address
string   $delimiter   —  The string representing the delimiter to use when verifying the MAC Address

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:17:04 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.