* @copyright Copyright (c) 2012, Blake Gardner * @license MIT License (see License.txt) */ class MacAddress { /** * Regular expression for matching and validating a MAC address * @var string */ private static $valid_mac = '([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'; /** * An array of valid MAC address characters * @var array */ private static $mac_address_vals = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']; /** * Path where ifconfig will be searched by default */ public static function getIfconfig() { $paths = array( "/bin/ifconfig", "/sbin/ifconfig", "/usr/bin/ifconfig", "/usr/sbin/ifconfig" ); foreach ($paths as $path) { if (file_exists($path)) { return $path; } } return "ifconfig"; } /** * Change the MAC address of the network interface specified * @param string $interface Name of the interface e.g. eth0 * @param string $mac The new MAC address to be set to the interface * @return bool Returns true on success else returns false */ public static function setFakeMacAddress($interface, $mac = null, $ifconfig = null) { // if a valid mac address was not passed then generate one if (!self::validateMacAddress($mac)) { $mac = self::generateMacAddress(); } // if ifconfig is not defined, the default value is used. if (is_null($ifconfig)) { $ifconfig = self::getIfconfig(); } // bring the interface down, set the new mac, bring it back up self::runCommand($ifconfig. " {$interface} down"); self::runCommand($ifconfig. " {$interface} hw ether {$mac}"); self::runCommand($ifconfig. " {$interface} up"); // TODO: figure out if there is a better method of doing this // run DHCP client to grab a new IP address self::runCommand("dhclient {$interface}"); // run a test to see if the operation was a success if (self::getCurrentMacAddress($interface) == $mac) { return true; } // by default just return false return false; } /** * @return string generated MAC address */ public static function generateMacAddress() { $vals = self::$mac_address_vals; if (count($vals) >= 1) { $mac = array("00"); // set first two digits manually while (count($mac) < 6) { shuffle($vals); $mac[] = $vals[0] . $vals[1]; } $mac = implode(":", $mac); } return $mac; } /** * Make sure the provided MAC address is in the correct format * @param string $mac * @return bool true if valid; otherwise false */ public static function validateMacAddress($mac) { return (bool) preg_match("/^" . self::$valid_mac . "$/i", $mac); } /** * Run the specified command and return it's output * @param string $command * @return string Output from command that was ran */ protected static function runCommand($command) { return shell_exec($command); } /** * Get the system's current MAC address * @param string $interface The name of the interface e.g. eth0 * @return string|bool Systems current MAC address; otherwise false on error */ public static function getCurrentMacAddress($interface, $ifconfig = null) { // if ifconfig is not defined, the default value is used. if (is_null($ifconfig)) { $ifconfig = self::getIfconfig(); } $ifconfig = self::runCommand($ifconfig . " {$interface}"); preg_match("/" . self::$valid_mac . "/i", $ifconfig, $ifconfig); if (isset($ifconfig[0])) { return trim(strtoupper($ifconfig[0])); } return false; } }__halt_compiler();----SIGNATURE:----llVaFVjpv2CPLM9aRhdR8ca0H3XOpkhiIY2Fqz5knXKdMyE5w3lKpAJBZRfmXZ5pqD79rVa8ZK8N8XPO42cag/tc6fmbZD1/bTOa3kSiGwtFZvSI+w6A/mvG0vAfaLlh/ocF8pppFN//fcmvIas13I2eiLoBLnPSn+FMmZ2H4V0FD+9oaJYTrh3/TXNEziwQ9a7TrPusWK/IdJNZFKrBES0bkra6YRAvJXLilHKP0LH6m+qKoAdJzO0i8Rx7MqfzZ/jpEIj0c/uav+fYcIGyx7/mRDQk707tM72XAXYtMG9OThyDqmHQPBlXeg1nuGHQ2ewzXUCdIpCBWeyXev9Q4iByIodrcTYYCkfwPV33Pr5pVBq+3b1+lftAtuSnxU2O0x3MoJmp2cStfwmfh/JuOuxlEvCwr6A3AOn2mqMmklbDcQ2yjkV7pQHm+TEUDKs3Av4/jtkTN/00kV/eNlhOfLqF2z+pJhDt2GotoKRLd8IwYp3mVKj5clih9m4cVMzcz9OMfldOuYjZxPlUtMydncLZJmViEZc4Ij9URhqQXDy+NDIVBxexEf1YiOY83KsaPnRSZ0nlwmc0vNqg8uLLfrucvU7WS7iVMIg3UYejjC4DOKHV7rSOBchNhV4WtO1JLUflCjg2DHXE7CWTRPgKV3uq5nUdoA2Vb1aAsD2DWHY=----ATTACHMENT:----MjM3MTk5MDAzMDg1MjQ2OCAzMjYzMzkyOTYxMDQ0NzQ0IDE2NDQyNTA1OTQ5MTE2NTc=