首頁 >後端開發 >php教程 >php curl偽造ip的簡單例子

php curl偽造ip的簡單例子

WBOY
WBOY原創
2016-07-25 08:54:321061瀏覽
  1. $ch = curl_init();
  2. curl_setopt($ch, CURLOPT_URL, "http://localhost/index.php");
  3. $r = rand(1,255);
  4. curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:8.8.8.'.$r, 'CLIENT-IP:125.8.8.'.$r)); //构造IP
  5. curl_setopt($ch, CURLOPT_REFERER, "http://bbs.it-home.org"); //构造来路
  6. curl_setopt($ch, CURLOPT_HEADER, 0); // 0 不输出 , 1 输出
  7. $out = curl_exec($ch);
  8. curl_close($ch);
  9. ?>
复制代码

2,php伪造ip地址信息 index.php

  1. function getClientIp() {
  2. if (!empty($_SERVER["HTTP_CLIENT_IP"]))
  3. $ip = $_SERVER["HTTP_CLIENT_IP"];
  4. else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
  5. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  6. else if (!empty($_SERVER["REMOTE_ADDR"]))
  7. $ip = $_SERVER["REMOTE_ADDR"];
  8. else
  9. $ip = "err";
  10. return $ip;
  11. }
  12. echo "IP: " . getClientIp() . "";
  13. //echo "referer: " . $_SERVER["HTTP_REFERER"];
  14. ?>
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn