How to change remote_addr header programmatically
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:
- DOCUMENT_ROOT = /home5/sdfsdfsdf/public_html
- GATEWAY_INTERFACE = CGI/1.1
- HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7
- HTTP_ACCEPT_ENCODING = gzip,deflate
- HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5
- HTTP_CONNECTION = keep-alive
- HTTP_COOKIE = __utma=47503804.842271267.1313228251.1313825844.1313950009.3
- HTTP_HOST = sdfsdfsdf.com
- HTTP_KEEP_ALIVE = 115
- 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
- PATH = /bin:/usr/bin
- QUERY_STRING =
- REDIRECT_STATUS = 200
- REMOTE_ADDR = 183.89.1.50
- REMOTE_PORT = 10136
- REQUEST_METHOD = GET
- REQUEST_URI = /test/print_headers.php
- SCRIPT_FILENAME = /sdfs/javaghsdfsdfsdfos/public_html/test/print_headers.php
- SCRIPT_NAME = /test/print_headers.php
- SERVER_ADDR = 66.147.242.173
- SERVER_ADMIN = webmaster@sdfsdfsdf.com
- SERVER_NAME = sdfdsfsdf.com
- SERVER_PORT = 80
- SERVER_PROTOCOL = HTTP/1.1
- SERVER_SIGNATURE = Apache Server at javaghost.com Port 80
- SERVER_SOFTWARE = Apache
- W3TC_ENC = _gzip
- file_gzip = /ramdisk/cpud/status
- PHP_SELF = /test/print_headers.php
- REQUEST_TIME = 1337838235
- argv = Array
- argc = 0 183.89.1.50
Like this post? Subscribe to my RSS feed and get loads more!

Leave a Reply