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

不言
发布: 2018-05-09 10:28:53
原创
2196人浏览过

这篇文章主要介绍了关于php使用curl伪造来源ip和refer的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

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

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

//随机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免费学习笔记(深入)”;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<?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使用curl伪造来源ip和refer的方法的详细内容,更多请关注php中文网其它相关文章!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号