您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 广元分类信息网,免费分类信息发布

php获取本机ip或远程地址

2025/3/23 18:17:43发布17次查看
// 111111111111 echo $_server['remote_addr']; // 2222222222222 function 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'; }
广元分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录