Gets the physical (MAC) address of the machine's network card.
Code:
. The code is as follows:
<?php
/**
* Get the physical (MAC) address of the machine's network card
* currently supports Win/linux system
**/
class Macaddinfo {
var $return _array = Array (); Returns a string array with a MAC address
var $mac _addr;
function Macaddinfo ($os _type) {
Switch (Strtolower ($os _type)) {
case "Linux":
$this->forlinux ();
break;
case "Solaris":
break;
case "UNIX":
break;
case "Aix":
break;
default:
$this->forwindows ();
break;
}
$temp _array = Array ();
foreach ($this->return_array as $value) {
if (Preg_match ("/[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f]/i", $value, $temp _array)) {
$this->mac_addr = $temp _array [0];
break;
}
}
unset ($temp _array);
return $this->mac_addr;
}
function forwindows () {
@exec ("Ipconfig/all", $this->return_array);
if ($this->return_array)
return $this->return_array;
else {
$ipconfig = $_server ["windir"]. "/system32/ipconfig.exe";
if (Is_file ($ipconfig))
@exec ($ipconfig. "/all", $this->return_array);
else
@exec ($_server ["windir"]. "/system/ipconfig.exe/all", $this->return_array);
return $this->return_array;
}
}
function Forlinux () {
@exec ("Ifconfig-a", $this->return_array);
return $this->return_array;
}
}
//Call Example
//$mac = new Macaddinfo (php_os);
//echo $mac->mac_addr;
?>