php搞定ip伪装的两种方式

<p>第一种:写了段代码伪装ip,原理是,客户访问网站,获取客户ip,伪装客户ip去访问数据源。采集后处理缓存到/tmp公共目录(省了空间,不占用自己的空间),然后输出到客户浏览器。代码如下:</p><pre class="brush:php;toolbar:false">$url=&quot;http://www.baidu.com&quot;; $host=&#39;www.baidu.com&#39;; $data=&quot;要发送的数据&quot;; $ip=&#39;121.186.1.57&#39;; $headers[&#39;CLIENT-IP&#39;]=$ip; $headers[&#39;X-FORWARDED-FOR&#39;]=$ip; $headerArr=array(); foreach($headersas$n=&gt;$v){ $headerArr[]=$n.&#39;:&#39;.$v; } $ch=curl_init(); $timeout=5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArr);//构造IP //我们在POST数据哦! curl_setopt($ch,CURLOPT_POST,1); //把post的变量加上 curl_setopt($ch,CURLOPT_POSTFIELDS,$data); $file_contents=curl_exec($ch); curl_close($ch); var_dump($file_contents);</pre><p>第二种:采用socket请求的方式</p><pre class="brush:php;toolbar:false">$host=&#39;192.168.1.100&#39;; $fp=fsockopen($host,80); if(!$fp) { die(&#39;创建连接失败,检查主机地址或网络连接&#39;); } //构造http请求串 $send=&quot;POST$pathHTTP/1.1\r\n&quot;; $send.=&quot;Host:$host\r\n&quot;; $send.=&quot;Content-type:application/x-www-form-urlencoded\r\n&quot;; //$send.=&#39;X-FORWARDED-FOR:8.8.8.8&#39;.&quot;\r\n&quot;; $send.=&quot;CLIENT-IP:$per_ip\r\n&quot;;//伪造IP $send.=&quot;Content-length:&quot;.strlen($data).&quot;\r\n&quot;; $send.=&quot;Connection:close\r\n\r\n&quot;; $send.=$data.&quot;\r\n\r\n&quot;; //发送请求 fwrite($fp,$send,strlen($send)); //读取返回信息 $back=&#39;&#39;; while(!feof($fp)) { $back.=fread($fp,1024); } fclose($fp); if(strpos($back,&#39;成功&#39;)) { $flag=&#39;成功&#39;; sleep(1); }</pre><p> </p>
RangeTime:0.008557s
RangeMem:205.56 KB
返回顶部 留言