投票限制获取mac地址

获取网卡的MAC地址原码;目前支持WIN/LINUX系统
获取机器网卡的物理(MAC)地址
 
class GetMacAddr{
    private $return_array = array();
    public $getaddr;
    public function getmac($os_type){
        switch(strtolower($os_type)){
            case "linux":
                $this->forLinux();
                break;
            case "unix":
                break;
            case "solaris":
                break;
            case "aix":
                break;
            default:
                $this->forWindows();
                break;
        }
 
        $temp_array = array();
        foreach($this->return_array  as $key => $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->getaddr = $temp_array[0];
            break;
        }
 
}
        unset($temp_array);
        return $this->getaddr;
    }
private 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;
        }
}
private function forLinux(){
    @exec('ifconfig -a',$this->return_array);
    return $this->return_array;
}
}
 
$mac = new GetMacAddr();
echo $mac->getmac(PHP_OS);
posted @ 2018-06-26 11:11  星云惊蛰  阅读(210)  评论(0)    收藏  举报