欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-29 12:45:37
本文实例讲述了php使用curl伪造来源ip和refer的方法。分享给大家供大家参考,具体如下: php curl伪造来源ip和来路refer实例代码1: //...

本文实例讲述了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(
 'client-ip:88.88.88.88',
 'x-forwarded-for:88.88.88.88',
);
$refer = 'http://www.baidu.com';
$ch = curl_init();
curl_setopt($ch, curlopt_url, 'http://localhost/phpdemo/test.php');
//伪造来源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网络编程技巧总结》、《php数组(array)操作技巧大全》、《php字符串(string)用法总结》、《php数据结构与算法教程》、《php程序设计算法总结》、《php运算与运算符用法总结》及《php常见数据库操作技巧汇总

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