php获取本机ip或远道地址
程序员文章站
2024-01-26 18:37:34
...
php获取本机ip或远程地址
// 111111111111echo $_SERVER['REMOTE_ADDR'];// 2222222222222function get_local_ip() { $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]))\Z/";//获取操作系统为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]); } } } }//获取操作系统为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]); } } } return '127.0.0.1';}
?
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
推荐阅读
-
php中获取真实IP地址与IP地址验证函数
-
【php】利用新浪api接口与php获取远程数据的步骤,获取IP地址,并获取相应的IP归属地
-
PHP根据IP地址判断城市实现城市切换或跳转代码_PHP教程
-
PHP获取IP地址以及IP地址所在位置
-
一台服务器php连接数据库,数据库地址却用了对外的ip,促成偶尔获取数据库连接句柄需要2s
-
php-PHP网站获取客户端IP地址固定都是北京的
-
php获取用户IPv4或IPv6地址的代码
-
php禁止某ip或ip地址段访问的方法_PHP教程
-
php禁止某ip或ip地址段访问的方法,phpip
-
php获取指定(访客)IP所有信息(地址、邮政编码、国家、经纬度等)的方法,所有信息经纬度_PHP教程
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论