CURL With Spoof ip address

2019-04-12 02:35发布

问题:

I heard from some friend that we can spoof our ip address in Curl with HTTP_X_FORWARDED_FOR , so i decide to test it and i create three file one to send Curl :

<?php

$ip = '1.1.1.1';
$url = "http://127.0.0.1/mydir/getdata.php";
$options = array (
    CURLOPT_CONNECTTIMEOUT => 1, // timeout on connect
    CURLOPT_TIMEOUT => 1, // timeout on response
    CURLOPT_MAXREDIRS => 1 ,
    CURLOPT_HTTPHEADER => array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"),
    CURLOPT_URL => $url ,
    );
$ch = curl_init();
curl_setopt_array ( $ch, $options );
print_r("+");
$result = curl_exec($ch);
curl_close($ch);

?>

one to get and save data :

<?php
    $file = 'ip.txt';
    $ipaddress = $_SERVER["REMOTE_ADDR"] .'\n';
    file_put_contents($file, $ipaddress, FILE_APPEND );
?>

and one to see the ip addresses as you can see 'ip.txt'.

But the problem is all i get in ip.txt is '127.0.0.1' and no spoof ip !!

If this is not working at all , What is the solution ?

Update :

I find out this :

No. libcurl operates on a higher level than so. Besides, faking IP address would imply sending IP packages with a made-up source address, and then you normally get a problem with intercepting the packages sent back as they would then not be routed to you!

Then how can i test a webpage with different IP address ?

I have some experience with programming language python , it can send a packet with spoof ip address but the problem is , it cant fully create TCP three way hand shaking process and the main website understand it.

标签: php curl ip