window系统上用PHP获取本地物理IP代码

<?php
$res=system("ipconfig -all");
$contents=trim(ob_get_clean());
$contents=str_replace("\r\n","",$contents);

$contents=explode("   ",$contents);
foreach($contents as $k=>&$v)
{
    
    $pre=substr($v,0,8);
    if($pre=="物理地址")
    {
        $ip=substr($v,36);
        break;
    }
}
var_dump($ip);
?>

 

posted @ 2016-03-02 10:21  李照耀  阅读(606)  评论(0编辑  收藏  举报