Home > php教程 > php手册 > body text

分享php如何使用curl伪造IP来源的方法

WBOY
Release: 2016-06-07 11:40:22
Original
1704 people have browsed it

php如何使用curl伪造IP来源的方法
php如何使用curl伪造IP来源<?php <br /> <br> $ch = curl_init();<br> <br> $url = "http://localhost/target_ip.php";<br> <br> $header = array('CLIENT-IP:58.68.44.61','X-FORWARDED-FOR:58.68.44.61',);<br> <br> curl_setopt($ch, CURLOPT_URL, $url);<br> <br> curl_setopt($ch, CURLOPT_HTTPHEADER, $header);<br> <br> curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);<br> <br> $page_content = curl_exec($ch);curl_close($ch);<br> <br> echo $page_content;<br> <br> ?>请求的目标文件---target_ip.php:<?php <br /> <br> echo getenv('HTTP_CLIENT_IP');<br> <br> echo getenv('HTTP_X_FORWARDED_FOR');<br> <br> echo getenv('REMOTE_ADDR');<br> <br> ?>目标文件target_ip里面的IP打印顺序是目前很多开源系统的IP获取顺序 访问fake_ip.php,看到结果: 58.68.44.61

58.68.44.61 127.0.0.1
最后,为大家提供二个小例子。 例1: <?php <br /> <br> $ch = curl_init();<br> <br> curl_setopt($ch, CURLOPT_URL, "http://localhost/2.php");<br> <br> curl_setopt($ch, CURLOPT_HTTPHEADER, <br>       array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8')); //构造<br> <br> IPcurl_setopt($ch, CURLOPT_REFERER, "http://bbs.it-home.org/ "); //构造来路<br> <br> curl_setopt($ch, CURLOPT_HEADER, 1);<br> <br> $out = curl_exec($ch);curl_close($ch);<br> <br> ?>例2: <?php <br /> <br> function getClientIp() {<br> <br> if (!empty($_SERVER["HTTP_CLIENT_IP"]))<br> <br> $ip = $_SERVER["HTTP_CLIENT_IP"];<br> <br> else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))<br> <br> $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];<br> <br> else if (!empty($_SERVER["REMOTE_ADDR"]))<br> <br> $ip = $_SERVER["REMOTE_ADDR"];<br> <br> else$ip = "err";<br> <br> return $ip;<br> <br> }<br> <br> echo "IP: " . getClientIp() . "";<br> <br> echo "referer: " . $_SERVER["HTTP_REFERER"];<br> <br> ?>转载原文地址:http://www.jb100.net/html/content-10-562-1.html

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template