html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

PHP取得MAC地址_PHP教程_编程技术

[ ] 已经帮助:人解决问题

PHP取得MAC地址
<?php

// 在linux下面取得MAC地址

// 在windows下面需要外部mac.exe,

// mac . exe为返回MAC地址的可执行程序,这个你们可以自己用DELPHi或者VC写 /

// 作者 hisun  <hisun@hisunweb.com>

// 任何疑问,请到 <a href="http://www.hisunweb.com" target="_blank">www.hisunweb.com</a> 留言,谢谢!

// 请尊重作者劳动成果

if ($_ENV["OS"] == "Windows_NT") {

    function getMAC($nic = "lo")

    {

        $mac_exe_file = "e:/mac.exe";

        if ($nic == 'lo') return "000000000000";

        if ($nic != 'eth0') {

            return false;

        }

        $s1 = trim(shell_exec($mac_exe_file));

        return strtolower($s1);

    }

} else {

    function getMAC($nic = "lo")

    {

        if ($nic == 'lo') return "000000000000";

        $s1 = shell_exec("/sbin/ifconfig " . escapeshellarg($nic) . " | head -1");

        if (strpos($s1, 'HWaddr') <= 1) {

            return false;

        } else {

            $a = explode('HWaddr', $s1);

            $s2 = str_replace(":", "", trim($a[1]));

            return strtolower($s2);

        }

    }

}

// echo "lo=>".getMAC()."<br>";

echo "eth0=>" . getMAC('eth0') . "<br>";

echo "eth1=>" . getMAC('eth1') . "<br>";

 

?>
 

5dFHTML5中文学习网 - HTML5先行者学习网
5dFHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助