I looked for the way to change REMOTE_ADDR header using HtmlUnit, or HttpClient. After some attempts realized that this is impossible. It is still possible on the level of socket programming but not http.

Because REMOTE_ADDR is not http request header. And even if somebody will success to send to server request with changed IP (REMOTE_ADDR) how she expects to get response?

Below the (PHP) code that prints out all of the request headers.

<html>

<body>

<ol>

<?php

   foreach($_SERVER as $h=>$v)

     if(ereg('(.+)',$h,$hp))

       echo "<li>$h = $v</li>\n";

   header('Content-type: text/html');

  ?>

</ol>

</body>

</html>

And this is (slightly censored) the result:

  1. DOCUMENT_ROOT = /home5/sdfsdfsdf/public_html
  2. GATEWAY_INTERFACE = CGI/1.1
  3. HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  4. HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7
  5. HTTP_ACCEPT_ENCODING = gzip,deflate
  6. HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5
  7. HTTP_CONNECTION = keep-alive
  8. HTTP_COOKIE = __utma=47503804.842271267.1313228251.1313825844.1313950009.3
  9. HTTP_HOST = sdfsdfsdf.com
  10. HTTP_KEEP_ALIVE = 115
  11. HTTP_USER_AGENT = Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28 GTB7.1
  12. PATH = /bin:/usr/bin
  13. QUERY_STRING =
  14. REDIRECT_STATUS = 200
  15. REMOTE_ADDR = 183.89.1.50
  16. REMOTE_PORT = 10136
  17. REQUEST_METHOD = GET
  18. REQUEST_URI = /test/print_headers.php
  19. SCRIPT_FILENAME = /sdfs/javaghsdfsdfsdfos/public_html/test/print_headers.php
  20. SCRIPT_NAME = /test/print_headers.php
  21. SERVER_ADDR = 66.147.242.173
  22. SERVER_ADMIN = webmaster@sdfsdfsdf.com
  23. SERVER_NAME = sdfdsfsdf.com
  24. SERVER_PORT = 80
  25. SERVER_PROTOCOL = HTTP/1.1
  26. SERVER_SIGNATURE = Apache Server at javaghost.com Port 80
  27. SERVER_SOFTWARE = Apache
  28. W3TC_ENC = _gzip
  29. file_gzip = /ramdisk/cpud/status
  30. PHP_SELF = /test/print_headers.php
  31. REQUEST_TIME = 1337838235
  32. argv = Array
  33. argc = 0 183.89.1.50

Filed under: javaphpseo

Like this post? Subscribe to my RSS feed and get loads more!