当前位置:Gxlcms > PHP教程 > php使用curl伪造来源ip和refer的方法示例

php使用curl伪造来源ip和refer的方法示例

时间:2021-07-01 10:21:17 帮助过:34人阅读

本文实例讲述了php使用curl伪造来源ip和refer的方法。分享给大家供大家参考,具体如下:

php curl伪造来源ip和来路refer实例代码1:

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

php curl伪造来源ip和来路refer实例代码2:

  1. <?php
  2. $postData = array(
  3. "user" => "root",
  4. "pwd" => "123456"
  5. );
  6. $headerIp = array(
  7. 'CLIENT-IP:88.88.88.88',
  8. 'X-FORWARDED-FOR:88.88.88.88',
  9. );
  10. $refer = 'http://www.baidu.com';
  11. $ch = curl_init();
  12. curl_setopt($ch, CURLOPT_URL, 'http://localhost/phpdemo/test.php');
  13. //伪造来源refer
  14. curl_setopt($ch, CURLOPT_REFERER, $refer);
  15. //伪造来源ip
  16. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerIp);
  17. //提交post传参
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  19. //...各种curl属性参数设置
  20. $out_put = curl_exec($ch);
  21. curl_close($ch);
  22. var_dump($out_put);

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《PHP网络编程技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《PHP运算与运算符用法总结》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

人气教程排行