Rumah > pembangunan bahagian belakang > tutorial php > PHP获取网卡的MAC地址原码,支持WIN/LINUX系统

PHP获取网卡的MAC地址原码,支持WIN/LINUX系统

WBOY
Lepaskan: 2016-07-29 08:49:47
asal
959 orang telah melayarinya

<code><span><span><?php </span><span>/**
* 获取网卡的MAC地址原码;目前支持WIN/LINUX系统
* 获取机器网卡的物理(MAC)地址
*/</span><span><span>class</span><span>GetMacAddr</span>
{</span><span>var</span><span>$return_array</span> = <span>array</span>(); <span>// 返回带有MAC地址的字串数组</span><span>var</span><span>$mac_addr</span>;
    <span>public</span><span><span>function</span><span>GetMacAddr</span><span>(<span>$os_type</span>)</span>
    {</span><span>switch</span> ( strtolower(<span>$os_type</span>) )
        {
            <span>case</span><span>"linux"</span>:
                <span>$this</span>->forLinux();
            <span>break</span>;
            <span>case</span><span>"solaris"</span>:
            <span>break</span>;
            <span>case</span><span>"unix"</span>:
            <span>break</span>;
            <span>case</span><span>"aix"</span>:
            <span>break</span>;
            <span>default</span>:
                <span>$this</span>->forWindows();
            <span>break</span>;
        }
        <span>$temp_array</span> = <span>array</span>();
        <span>foreach</span> ( <span>$this</span>->return_array <span>as</span><span>$value</span> )
        {
            <span>if</span> (preg_match(<span>"/[0-9a-f][0-9a-f][:-]"</span>.<span>"[0-9a-f][0-9a-f][:-]"</span>.<span>"[0-9a-f][0-9a-f][:-]"</span>.<span>"[0-9a-f][0-9a-f][:-]"</span>.<span>"[0-9a-f][0-9a-f][:-]"</span>.<span>"[0-9a-f][0-9a-f]/i"</span>,<span>$value</span>,<span>$temp_array</span> ))
            {
                <span>$this</span>->mac_addr = <span>$temp_array</span>[<span>0</span>];
                <span>break</span>;
            }
        }
        <span>unset</span>(<span>$temp_array</span>);
        <span>return</span><span>$this</span>->mac_addr;
    }  

    <span>public</span><span><span>function</span><span>forWindows</span><span>()</span>
    {</span>
        @exec(<span>"ipconfig /all"</span>, <span>$this</span>->return_array);
        <span>if</span> ( <span>$this</span>->return_array )
            <span>return</span><span>$this</span>->return_array;
        <span>else</span>
        {
            <span>$ipconfig</span> = <span>$_SERVER</span>[<span>"WINDIR"</span>].<span>"\system32\ipconfig.exe"</span>;
            <span>if</span> ( is_file(<span>$ipconfig</span>) )
                @exec(<span>$ipconfig</span>.<span>" /all"</span>, <span>$this</span>->return_array);
            <span>else</span>
                @exec(<span>$_SERVER</span>[<span>"WINDIR"</span>].<span>"\system\ipconfig.exe /all"</span>, <span>$this</span>->return_array);
            <span>return</span><span>$this</span>->return_array;
        }
    }  

    <span>public</span><span><span>function</span><span>forLinux</span><span>()</span>
    {</span>
        @exec(<span>"ifconfig -a"</span>, <span>$this</span>->return_array);
        <span>return</span><span>$this</span>->return_array;
    }
}
<span>//方法使用</span><span>$mac</span> = <span>new</span> GetMacAddr(PHP_OS);
<span>echo</span><span>$mac</span>->mac_addr;
</span></span></code>
Salin selepas log masuk
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了PHP获取网卡的MAC地址原码,支持WIN/LINUX系统,包括了linux系统,Mac地址方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan