三个参数
HTTP_CLIENT_IP
HTTP_X_FORWARDED_FOR
REMOTE_ADDR
服务器IP获取
function _get_client_ip() {
$clientip = '';
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$clientip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$clientip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$clientip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$clientip = $_SERVER['REMOTE_ADDR'];
}
preg_match("/[\d\.]{7,15}/", $clientip, $clientipmatches);
$clientip = $clientipmatches[0] ? $clientipmatches[0] : 'unknown';
return $clientip;
}
很多服务器端一般都采用了$_SERVER['REMOTE_ADDR']来获取客户端的真实ip,这是在传输层就已经决定的地址,无法通过CURL进行修改。remote_addr并不一定就是客户端的真实IP,不过它是真实的一个地址( 最后一个代理服务器 IP)。
简单IP伪造
curl "http://www.jianshu.com" -H "X-Forwarded-For:8.8.8.8" -H "CLIENT-IP:8.8.8.8"