Example code of phpcurl spoofing IP source

Source: Internet
Author: User
The file fake_ip.php from which curl sends the request: the code phpcurl is used to forge the instance code of the IP source. phpcurl is used to forge the instance code of the IP source. curl sends the request file fake_ip.php:
Code




Copy the code as follows:
$ Ch = curl_init ();
$ Url = "http: // localhost/target_ip.php ";
$ Header = array (
'Client-IP: 58.68.44.61 ',
'X-FORWARDED-FOR: 58.68.44.61 ',
);
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
$ Page_content = curl_exec ($ ch );
Curl_close ($ ch );
Echo $ page_content;
?>


Target file target_ip.php of the request:
Copy the code as follows:
Echo getenv ('http _ CLIENT_IP ');
Echo getenv ('http _ X_FORWARDED_FOR ');
Echo getenv ('remote _ ADDR ');
?>


The IP address printing sequence in the target file target_ip is the IP address acquisition sequence of many open-source systems.
Access fake_ip.php and see the result:
58.68.44.61
58.68.44.61
127.0.0.1
Instance
CURL is really powerful and can forge IP addresses and sources.
1. php requests 2.php.


1. php code:


Copy the code as follows:
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, "http: // localhost/2.php ");
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('x-FORWARDED-FOR: 8.8.8.8 ', 'client-IP: 8.8.8.8'); // Construct an IP address
Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.jb51.net/"); // Construct a path
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
$ Out = curl_exec ($ ch );
Curl_close ($ ch );




2. the php code is as follows:


Copy the code as follows:
Function getClientIp (){
If (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"])
$ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
Else if (! Empty ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
$ Ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
Else if (! Empty ($ _ SERVER ["REMOTE_ADDR"])
$ Ip = $ _ SERVER ["REMOTE_ADDR"];
Else
$ Ip = "err ";
Return $ ip;
}
Echo "IP:". getClientIp ()."";
Echo "referer:". $ _ SERVER ["HTTP_REFERER"];


Forged successfully. does this provide a good IP address change solution for the "ticket swiping" friend?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.