理论上不能实现,实践中也不能实现
现实的变通解决办法:
写个activeX插件,...
单纯的web语言实现不了这样的功能

解决方案 »

  1.   

    但是,我们浏览网页时发出请求,如果没有MAC地址,服务器如何知道把结果传到客户端呢?
      

  2.   

    今天刚搜到的.你看看.
    PHP :: 获取计算机 IP 地址及网卡 MAC 地址
    用 PHP 写了个函数,在 Linux 下使用命令行运行方式,获取当前计算机的 IP 地址及网卡 MAC 地址。
    <?php
    //    filename: get_eth.php
    function get_network_interface()
    {
        $ips = array();
        $info = `/sbin/ifconfig -a`;
        $infos = explode("\n\n", $info);
        foreach ($infos as $info) {
            $info = trim($info);
            if (substr($info, 0, 3) == 'eth') {
                $lines = explode("\n", $info);
                $interface = substr($lines[0], 0, strpos($lines[0], ' '));
                $mac = substr($lines[0], strlen($lines[0])-19);
                preg_match('/addr:([0-9\.]+)/i', $lines[1], $matches);
                $ip = $matches[1];
                $ips[$interface] = array('ip' => $ip, 'mac' => $mac);
            }   //end if
        }   //end foreach
        return $ips;
    }   //end function
    $interfaces = get_network_interface();
    print_r($interfaces);
    ?>
    运行输出结果如下:
    $ php get_eth.php
    Array
    (
        [eth0] => Array
            (
                [ip] => 192.168.212.68
                [mac] => 00:0C:29:F7:3D:38
            ))
    UPDATE 4:50 pm: 加入了 Windows 下的兼容性代码,修改之后的函数为:
    <?php
    //    filename: get_eth.php
    function get_network_interface()
    {
        $os = strtolower(substr(PHP_OS, 0, 3));
        $ips = array();
        if ($os == 'win') {
            $info = `ipconfig /all`;
            $infos = explode("\n", $info);
            $max = count($infos);
            for ($i = 0; $i < $max; $i++) {
                $line = trim($infos[$i]);
                if (substr($line, 0, 8) == 'Physical') {    //网卡物理地址所在行
                    $segments = explode(':', $line);
                    $mac = str_replace('-', ':', trim($segments[1]));
                    $i += 2;    //跳到后两行,即 IP 地址所在行
                    $segments = explode(':', $infos[$i]);
                    $ip = trim($segments[1]);
                    $ips[] = array('ip' => $ip, 'mac' => $mac); 
                }   //end if
            }   //end for        
        } else if ($os == 'lin') {
            $info = `/sbin/ifconfig -a`;
            $infos = explode("\n\n", $info);
            foreach ($infos as $info) {
                $info = trim($info);
                if (substr($info, 0, 3) == 'eth') {
                    $lines = explode("\n", $info);
                    $interface = substr($lines[0], 0, strpos($lines[0], ' '));
                    $mac = substr($lines[0], strlen($lines[0])-19);
                    preg_match('/addr:([0-9\.]+)/i', $lines[1], $matches);
                    $ip = $matches[1];
                    $ips[$interface] = array('ip' => $ip, 'mac' => $mac);
                }   //end if
            }   //end foreach
        }   //end if
        return $ips;
    }   //end function
    $interfaces = get_network_interface();
    print_r($interfaces);
    ?>
    在 Windows 2000/2003 命令行运行结果如下:
    C:\php>php.exe get_eth.php
    Array
    (
        [0] => Array
            (
                [ip] => 192.168.212.244
                [mac] => 00:E0:4C:00:4D:0C
            )    [1] => Array
            (
                [ip] => 192.168.200.1
                [mac] => 00:50:56:C0:00:01
            )
    )
    以上函数对于多网卡计算机一样适用。 
    Posted by: Nio on 2004-09-16 | 4:02 pm
    COMMENTS
    偶得运行结果。Array
    (
    [0] => Array
    (
    [ip] => Yes
    [mac] => 00:E0:FE:39:4E:D3
    )[1] => Array
    (
    [ip] => fe80
    [mac] => FF:FF:FF:FF:FF:FF:FF:FF
    )[2] => Array
    (
    [ip] => fe80
    [mac] => C0:A8:00:36
    ))Posted by: episome on Oct 19, 05 | 10:58 am
    这个函数的代码并不能保证所有操作系统都可以顺利获取到结果,需要根据具体命令的输出格式进行微调修改 ;)Posted by: Nio on Oct 21, 05 | 9:11 pm
      

  3.   

    呵呵,楼上的代码只是针对获取服务器本身的MAC地址,并不能获取客户端的MAC地址。在IE下使用ActiveX控件,在Firxfox下使用扩展。当然,也可以让客户自己填写
      

  4.   

    获取客户端网卡MAC地址和IP地址的几种方法(一)作者:代码乱了       在做B/S结构的系统时,我们常常需要获取客户端的一些信息,如IP和MAC,以结合身份验证。在ASP.NET中,要获取服务器端的MAC很容易,但是要获取客户端的MAC的地址确要花费一翻心思,通常的做法是调用Win32API或直接调用nbtstat命令,这样做有很多问题,而另一种方法就是直接用客户端脚本,我们这里用Javascript,这样做的好处是不需要服务器端进行处理,有客户端自行获取,传递到服务器端,且速度和可靠性都比在服务器端获取好。
            具体实现的html和javascript如下:
    <HTML><HEAD><TITLE>WMI Scripting HTML</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <SCRIPT language=JScript event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for=foo>
     document.forms[0].txtMACAddr.value=unescape(MACAddr);
     document.forms[0].txtIPAddr.value=unescape(IPAddr);
     document.forms[0].txtDNSName.value=unescape(sDNSName);
     //document.formbar.submit();
      </SCRIPT><SCRIPT language=JScript event=OnObjectReady(objObject,objAsyncContext) for=foo>
       if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true)
       {
        if(objObject.MACAddress != null && objObject.MACAddress != "undefined")
        MACAddr = objObject.MACAddress;
        if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined")
        IPAddr = objObject.IPAddress(0);
        if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined")
        sDNSName = objObject.DNSHostName;
        }
      </SCRIPT><META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
    <BODY>
    <OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></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><FORM id=formfoo name=formbar action=NICPost.asp method=post><INPUT value=00:05:5D:0E:C7:FA name=txtMACAddr> <INPUT value=192.168.0.2 name=txtIPAddr> <INPUT value=typ name=txtDNSName> </FORM></BODY></HTML>
            其实最关键的还是用到两个ActiveX:
            <OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>
            <OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>
            不过这两个ActiveX都是系统自带,不用去下载或注册。
            接下来的工作就是用脚本和ActiveX交互,脚本可以是js或Vbs都可以,不过我个人喜欢用js。下一篇我将具体的谈谈在服务器端结合.net获取客户端MAC的方法,并比较这几中方法的优劣。
      

  5.   

    PHP获取网卡MAC地址的方法- -
                                           做一个限定用户登录的东西时用到这段代码,可能还有人会用到,拿出来分享......
    <?php
    @exec("ipconfig /all",$array);
    for($Tmpa;$Tmpa<count($array);$Tmpa++){
          if(eregi("Physical",$array[$Tmpa])){
                $mac=explode(":",$array[$Tmpa]);
                echo $mac[1];
          }
    }
    ?>