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

CURL函数库

PHP中的CURL函数库(Client URL Library Function)如下:

  • curl_close — 关闭一个curl会话
  • curl_copy_handle — 拷贝一个curl连接资源的所有内容和参数
  • curl_errno — 返回一个包含当前会话错误信息的数字编号
  • curl_error — 返回一个包含当前会话错误信息的字符串
  • curl_exec — 执行一个curl会话
  • curl_getinfo — 获取一个curl连接资源句柄的信息
  • curl_init — 初始化一个curl会话
  • curl_multi_add_handle — 向curl批处理会话中添加单独的curl句柄资源
  • curl_multi_close — 关闭一个批处理句柄资源
  • curl_multi_exec — 解析一个curl批处理句柄
  • curl_multi_getcontent — 返回获取的输出的文本流
  • curl_multi_info_read — 获取当前解析的curl的相关传输信息
  • curl_multi_init — 初始化一个curl批处理句柄资源
  • curl_multi_remove_handle — 移除curl批处理句柄资源中的某个句柄资源
  • curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
  • curl_setopt_array — 以数组的形式为一个curl设置会话参数
  • curl_setopt — 为一个curl设置会话参数
  • curl_version — 获取curl相关的版本信息
  • curl_init()函数的作用初始化一个curl会话,curl_init()函数唯一的一个参数是可选的,表示一个url地址.
  • curl_exec()函数的作用是执行一个curl会话,唯一的参数是curl_init()函数返回的句柄.
  • curl_close()函数的作用是关闭一个curl会话,唯一的参数是curl_init()函数返回的句柄.

实例代码1

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

//随机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;

}

php1.31 KB© 一为忆

实例代码2

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

<?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);

你可能感兴趣的