Location: PHPKode > scripts > MAC Address Generator > class.MACAddress.php
<?php
/**
 * This is class for generating MAC Address
 *
 * @author Nitesh Apte
 * @copyright Nitesh Apte, 2010
 * @version 1.0
 * @access public
 * @License GPL
 */

class MACAddress 
{
    /**
     * MAC Address prefix variable instance
     *
     * @access private
     * @var String $_macPrefix MAC Address prefix.
     */
    private $_macPrefix = '00-';
    
    /**
     * MAC Address prefix variable instance for Organization. The first three characters are unique for certain organization.
     *
     * @access private
     * @var String $_macPrefix MAC Address prefix for Organization(Change as per your requirement)
     */
    private $_macORGPrefix = '00-OR-GA-';

    /**
     * MAC Address variable instance
     *
     * @access private
     * @var String $_macAddress MAC Address 
     */
    private $_macAddress;

    /**
     * Method for generating MAC Address
     *
     * @param none
     * @return String MAC Address
     */
     public function _generateMAC()
     {
        $this->_macChars = md5(uniqid(mt_rand(), TRUE));
        
        $this->_macAddress = substr($this->_macChars, 0,2) . '-';
        $this->_macAddress .= substr($this->_macChars, 8,2) . '-';
        $this->_macAddress .= substr($this->_macChars, 12,2) . '-';
        $this->_macAddress .= substr($this->_macChars, 16,2) . '-';
        $this->_macAddress .= substr($this->_macChars, 20,2);
        return $this->_macPrefix.$this->_macAddress;
     }

    /**
     * Method for generating MAC Address. The first three characters are unique for certain organization.
     *
     * @param none
     * @return String MAC Address
     */
     public function _generateMAC2()
     {
        $this->_macChars = md5(uniqid(mt_rand(), TRUE));
        
        $this->_macAddress = substr($this->_macChars, 0,2) . '-';
        $this->_macAddress .= substr($this->_macChars, 8,2) . '-';
        $this->_macAddress .= substr($this->_macChars, 12,2);
        return $this->_macORGPrefix.$this->_macAddress;
     }
}
$obj = new MACAddress;
echo $obj->_generateMAC();
echo $obj->_generateMAC2();
?> 
Return current item: MAC Address Generator