php curl伪造来源ip和来路refer实例代码1:
1 //随机IP 2 function Rand_IP(){ 3 4 $ip2id= round(rand(600000, 2550000) / 10000); //第一种方法,直接生成 5 $ip3id= round(rand(600000, 2550000) / 10000); 6 $ip4id= round(rand(600000, 2550000) / 10000); 7 //下面是第二种方法,在以下数据中随机抽取 8 $arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211"); 9 $randarr= mt_rand(0,count($arr_1)-1); 10 $ip1id = $arr_1[$randarr]; 11 return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id; 12 } 13 14 //抓取页面内容 15 function Curl($url){ 16 $ch2 = curl_init(); 17 $user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";//模拟windows用户正常访问 18 curl_setopt($ch2, CURLOPT_URL, $url); 19 curl_setopt($ch2, CURLOPT_TIMEOUT, 10); 20 curl_setopt($ch2, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.Rand_IP(), 'CLIENT-IP:'.Rand_IP())); 21 //追踪返回302状态码,继续抓取 22 curl_setopt($ch2, CURLOPT_HEADER, true); 23 curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); 24 curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true); 25 26 curl_setopt($ch2, CURLOPT_NOBODY, false); 27 curl_setopt($ch2, CURLOPT_REFERER, 'http://www.baidu.com/');//模拟来路 28 curl_setopt($ch2, CURLOPT_USERAGENT, $user_agent); 29 $temp = curl_exec($ch2); 30 curl_close($ch2); 31 return $temp; 32 }
php curl伪造来源ip和来路refer实例代码2:
1 <?php 2 3 $postData = array( 4 "user" => "root", 5 "pwd" => "123456" 6 ); 7 8 $headerIp = array( 9 'CLIENT-IP:88.88.88.88', 10 'X-FORWARDED-FOR:88.88.88.88', 11 ); 12 13 $refer = 'http://www.nidagelail.com'; 14 15 $ch = curl_init(); 16 curl_setopt($ch, CURLOPT_URL, 'http://localhost/phpdemo/test.php'); 17 18 //伪造来源refer 19 curl_setopt($ch, CURLOPT_REFERER, $refer); 20 //伪造来源ip 21 curl_setopt($ch, CURLOPT_HTTPHEADER, $headerIp); 22 23 //提交post传参 24 curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 25 //...各种curl属性参数设置 26 $out_put = curl_exec($ch); 27 curl_close($ch); 28 var_dump($out_put);