代码贴 - 查询本机ip
修一个小bug 凌梦云kangle脚本时不时获取本机ip失效 然后就自己写了这么一个api
凌梦云kangle一键脚本
yum -y install wget;wget http://kangle.mxftp.cn/start;sh start
下面贴接口代码
<?php
/*
* @Author: Qicloud
* @Title: API
* @Project: 查询本机ip
* @QQ: 66547997
* @Date: 2020-12-24 22:55:39
* @LastEditTime: 2020-12-24 22:56:02
* @你不懂我的热爱,又怎知我不明白
*/
function getIP()
{
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
foreach ($matches[0] as $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
}
return $ip;
}
echo getIP();
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 七云's Blog!