Jump to content

how to display a mac address?


c0ldfyr3

Recommended Posts

i am new to PhP...

 

 

i have this scripts however i get no out put just a parse error.

 


$mac = &new NtMacAddress();
		echo 'SERVER MAC: '.$mac->getMac( 'server' ).'<br />CLIENT MAC: '.$mac->getMac( 'client' );
  

class NtMacAddress {

 		NtMacAddress->getMac( $what:String ):String

function getMac( $what ) {
	$what = &strtolower( $what );
	if( $what == 'server' ) {
		return $this->__server_macaddress();
	}
	elseif( $what == 'client' ) {
		return $this->__client_macaddress();
	}
	else {
		return '\'client\' or \'server\' ?';
	}
}


  Private method __server_macaddress. Returns server mac-address if is readable.

 		NtMacAddress->__server_macaddress():String


function __server_macaddress() {
	$output = Array();
	exec( 'netstat -r', $output );
	for( $a = 0, $b = &count( $output ); $a < $b; $a++ ) {
		if( preg_match( "/(?i)([a-z0-9]{2} ){6}/", $output[$a] ) == true ) {
			$macaddress = &$output[$a];
			$uniquekey = &md5( $macaddress );
			$output[$a] = &preg_replace( "/(?i)([^a-z0-9]?)([a-z0-9]{2} ){6}/i", "\\1 {$uniquekey} ", $output[$a] );
			$output[$a] = &explode( " {$uniquekey} ", $output[$a] );
			$uniquekey = Array( trim( $output[$a][0] ), trim( $output[$a][1] ) );
			$macaddress = &str_replace( $uniquekey, "", $macaddress );
			return trim( $macaddress );
		}
	}
	return 'not found';
}


NtMacAddress->__client_macaddress():String


function __client_macaddress() {
	$output = Array();
	exec( 'nbtstat -A '.$_SERVER['REMOTE_ADDR'], $output );
	$reg = '([a-f0-9]{2}\-){5}([a-f0-9]{2})';
	for( $a = 0, $b = &count( $output ); $a < $b; $a++ ) {
		if( preg_match( "/(?i){$reg}/", $output[$a] ) == true ) {
		        return preg_replace( "/(?iU)(.+)({$reg})(.)/", "\\2", $output[$a] );
		}
	}
	return 'not found';
}
}

Link to comment
https://forums.phpfreaks.com/topic/121640-how-to-display-a-mac-address/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.