一叶孤舟

简单程序,简单人生,分享程序,分享人生。

JS配合PHP获取客户端MAC地址

<SCRIPT language="JScript" event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for="foo"> 
document.forms[0].lbMacAddr.value=unescape(MACAddr); 
</SCRIPT>
<SCRIPT language="JScript" event="OnObjectReady(objObject,objAsyncContext)" for="foo"> 
if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true && objObject.MACAddress != null && objObject.MACAddress != "undefined")MACAddr = objObject.MACAddress; 
</SCRIPT>
<OBJECT id="locator" classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" >
</OBJECT>
<OBJECT id="foo" classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" >
</OBJECT>
<SCRIPT language="JScript"> 
var service = locator.ConnectServer(); 
var MACAddr ; 
var IPAddr ; 
var DomainAddr; 
var sDNSName; 
service.Security_.ImpersonationLevel=3; 
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration'); 
</SCRIPT>



php:
<?php
class GetMacAddr
{
        var $return_array = array(); 
        var $mac_addr;
        
        function GetMacAddr($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"]."system32ipconfig.exe";
                        if ( is_file($ipconfig) )
                                @exec($ipconfig." /all", $this->return_array);
                        else
                                @exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->return_array);
                        return $this->return_array;
                }
        }
        function forLinux()
        {
                @exec("ifconfig -a", $this->return_array);
                return $this->return_array;
        }
}
?>
<?
$mac = new GetMacAddr(PHP_OS);
echo $mac->mac_addr;
//获取客户端
/*$result=`arp -a $REMOTE_ADDR`;
//$result=`nbtstat -a $REMOTE_ADDR`;
print_r($result);*/
?>


阅读更多
个人分类: PHP
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭