• 获取本机IP非127.0.0.1


    protected function GetiP()
        {
        $preg="/A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5])).){3}(([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))/";
        //获取操作系统为win2000/xp、win7的本机IP真实地址
        exec("ipconfig",$out,$stats);
            if(!empty($out))
            {
                foreach($out AS $row)
                {
                    if(strstr($row,"IP") && strstr($row,":") && !strstr($row,"IPv6"))
                    {
                    $tmpIp = explode(":", $row);
                        if(preg_match($preg,trim($tmpIp[1])))
                        {
                            return trim($tmpIp[1]);
                        }
                    }
                }
            }        
        }
        public function actionGetips(){
            $ip = $this->Getip();
            echo $ip;
        }

    //获取操作系统为linux类型的本机IP真实地址
    exec("ifconfig",$out,$stats);
    if(!empty($out))
    {
        if(isset($out[1]) && strstr($out[1],'addr:'))
        {
            $tmpArray = explode(":", $out[1]);
            $tmpIp = explode(" ", $tmpArray[1]);
            if(preg_match($preg,trim($tmpIp[0])))
            {
                return trim($tmpIp[0]);
            }
        }
    }

  • 相关阅读:
    二叉排序树和平衡二叉树
    博客首页特效整理2
    博客首页特效整理
    19-20下学期思维导图
    19-20下学期第一次作业问卷调查回答
    c++实现五子棋游戏
    c++实现扫雷游戏
    c++实现2048游戏
    c++实现推箱子游戏
    C++实现贪吃蛇小游戏
  • 原文地址:https://www.cnblogs.com/jhy-ocean/p/5401914.html
Copyright © 2020-2023  润新知