首頁  >  文章  >  後端開發  >  php使用curl偽造來源ip和refer的方法

php使用curl偽造來源ip和refer的方法

不言
不言原創
2018-05-09 10:28:531796瀏覽

這篇文章主要介紹了關於php使用curl偽造來源ip和refer的方法,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

本文實例講述了php使用curl偽造來源ip和refer的方法。分享給大家供大家參考,具體如下:

php curl偽造來源ip與來路refer實例碼1:

//随机IP
function Rand_IP(){
 $ip2id= round(rand(600000, 2550000) / 10000); //第一种方法,直接生成
 $ip3id= round(rand(600000, 2550000) / 10000);
 $ip4id= round(rand(600000, 2550000) / 10000);
 //下面是第二种方法,在以下数据中随机抽取
 $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");
 $randarr= mt_rand(0,count($arr_1)-1);
 $ip1id = $arr_1[$randarr];
 return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id;
}
//抓取页面内容
function Curl($url){
  $ch2 = curl_init();
  $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用户正常访问
  curl_setopt($ch2, CURLOPT_URL, $url);
  curl_setopt($ch2, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch2, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.Rand_IP(), 'CLIENT-IP:'.Rand_IP()));
//追踪返回302状态码,继续抓取
  curl_setopt($ch2, CURLOPT_HEADER, true); 
  curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); 
  curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch2, CURLOPT_NOBODY, false);
  curl_setopt($ch2, CURLOPT_REFERER, 'http://www.baidu.com/');//模拟来路
  curl_setopt($ch2, CURLOPT_USERAGENT, $user_agent);
  $temp = curl_exec($ch2);
  curl_close($ch2);
  return $temp;
}

php curl偽造來源ip與來路refer實例碼2:

<?php
$postData = array(
 "user" => "root",
 "pwd" => "123456"
);
$headerIp = array(
 &#39;CLIENT-IP:88.88.88.88&#39;,
 &#39;X-FORWARDED-FOR:88.88.88.88&#39;,
);
$refer = &#39;http://www.baidu.com&#39;;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, &#39;http://localhost/phpdemo/test.php&#39;);
//伪造来源refer
curl_setopt($ch, CURLOPT_REFERER, $refer);
//伪造来源ip
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerIp);
//提交post传参
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
//...各种curl属性参数设置
$out_put = curl_exec($ch);
curl_close($ch);
var_dump($out_put);

#以上就是本篇文章的全部內容了,更多相關內容請關注PHP中文網。

相關推薦:

php curl批次實作可控制並發非同步的操作

##

以上是php使用curl偽造來源ip和refer的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn