php CURL fake IP and source implementation program_PHP tutorial

WBOY
Release: 2016-07-20 11:11:10
Original
832 people have browsed it

Forging the IP source is a very simple thing for PHP. We only need to use php curl to achieve the forged IP source. You can write the IP address as you like.

Example

The code is 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'));//IP
curl_setopt($ch, CURLOPT_REFERER, "http://www.hzhuti.com/ ");   //来路
curl_setopt($ch, CURLOPT_HEADER, 1);
$out = curl_exec($ch);
curl_close($ch);

Copy code

 代码如下 复制代码

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"];

用1.php 请求 2.php,输出结果:

IP:8.8.8.8  referer:http://www.hzhuti.com

$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'));//IP

curl_setopt($ch, CURLOPT_REFERER, "http://www.hzhuti.com / "); // Origin

curl_setopt($ch, CURLOPT_HEADER, 1);

$out = curl_exec($ch);
curl_close($ch);




2.php code:

echo "referer: " . $_SERVER["HTTP_REFERER"];
The code is as follows
Copy code


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() . "";
Use 1.php to request 2.php, the output result is:
IP: 8.8.8.8 referer:http://www.hzhuti.com

The forgery was successful. Is this a good way to change IP for collecting friends? plan! ! Of course, friends who want to prevent fraud should also pay attention to CURL Function Library (Client URL Library Function) in PHP curl_close — close a curl session curl_copy_handle — copy a curl connection resource All contents and parameters of curl_errno — Returns a numeric number containing error information for the current session curl_error — Returns a string containing error information for the current session curl_exec — Execute a curl session curl_getinfo — Get Information about a curl connection resource handle
curl_init — initialize a curl session curl_multi_add_handle — add a separate curl handle resource to the curl batch session curl_multi_close — close a batch handle resource
curl_multi_exec — parsing A curl batch handle
curl_multi_getcontent — Returns the text stream of the obtained output curl_multi_info_read — Gets the relevant transmission information of the currently parsed curl curl_multi_init — Initializes a curl batch handle resource curl_multi_remove_handle — Remove A handle resource in the curl batch handle resourcecurl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"curl_setopt_array — Set session parameters for a curl in the form of an arraycurl_setopt — Set session parameters for a curl curl_version — Get curl-related version information The role of the curl_init() function is to initialize a curl session. The only parameter of the curl_init() function is optional. Represents a url address. The curl_exec() function is used to execute a curl session. The only parameter is the handle returned by the curl_init() function. The curl_close() function is used to close a curl session. The only parameter is the handle returned by the curl_init() function. http://www.bkjia.com/PHPjc/444658.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444658.htmlTechArticleFake IP source is a very simple thing for php, we only need to use php curl to achieve it Forge the source of the IP. You can write the IP address as you like. Example code is as follows Copy the code...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template