Return True Remote Ip from Magic Router

Include Standard Routing, Port Foward, Header Forward, Auto Switch, QoS and Remote Management.

Return True Remote Ip from Magic Router

Postby admin » Fri Oct 14, 2011 3:46 pm

Obviously, if use magic router as the service listen port and forward to final application server, all remote ip is 127.0.0.1 or local host computer ip, ie. 192.168.1.x.

We provide the following way to get true remote ip. Remember to set allowed ip subnet, otherwise remoteip.html will return nothing.

Internet Explorer to return, if you know the port:
http://192.168.1.1:8888/remoteip.html?P=12345

Visual Basic sample code to get true remote ip from Magic Router:
Set oXML = CreateObject("Microsoft.XMLHTTP")
oXML.Open "Get", "http://192.168.1.1:8888/remoteip.html?P=" & Socket(Index).RemotePort, False
oXML.Open "Get", "http://192.168.1.1:8888/remoteip.html?P=" & Socket(Index).RemotePort & "&T=" & Int(Rnd() * 1000000), False 'using localhost is very slow response, use 192.168.1.x instead, but need to set allowed ip subnet in remote management to 192.168.1.0 and password
oXML.Send
Debug.Print oXML.ResponseText

PHP to return:
<?php
//you can overwrite $_SERVER['REMOTE_ADDR'], put this overwrite coding at the very beginning of php pages.
//echo "Before overwrite ip: ".$_SERVER['REMOTE_ADDR']."<br>";
$_SERVER['REMOTE_ADDR'] = GetRemoteIP();
//echo "After overwrite ip: ".$_SERVER['REMOTE_ADDR'];

function GetRemoteIP()
{
$handle = @fopen("http://192.168.1.1:8888/remoteip.html?P=".$_SERVER['REMOTE_PORT']."&T=".rand(), "r"); // where rand() is must, force to update, not to check cache
if ($handle) {
$contents = stream_get_contents($handle);
if ($contents) {
$RemoteIP = $contents;
} else {
$RemoteIP = '127.0.0.1'; //do not return non ip string if fail, return a default.
}
} else {
$RemoteIP = '127.0.0.1'; //do not return non ip string if fail, return a default.
}
fclose($handle);
return $RemoteIP;
}
?>

TrueIp.jpg


PASS IP Option in Remote Management
If you connect Magic Router to Magic Router, the second Magic Router will always return the ip (search remoteip.html for reference ) of 1st Magic Router. Therefore you need to enable PASS IP in the first Magic Router, the first 1 will pass the true remote ip to next connected Magic Router. The second Magic Router do not need to enable. If you enable it, the final application server will receive incorrect data.

PASS IP is support in Standard Routing, and Router Mode = Standalone or Router Mode = Server, not support in Agent/reverse connection.

What is the purpose of PASS IP ?
Passing ip to the last Magic Router, web server (Apache) can query the true remote ip by http://192.168.1.x:8888/remoteip.html?P=12345
PASS IP is special design for Auto Switch / Load Balancing. If there are many Magic Router connected, remote ip of socket will become meaningless, you need to enable PASS IP. The last Magic Router connected to application server is not needed.
admin
Site Admin
 
Posts: 159
Joined: Wed Aug 24, 2011 8:31 am

Return to Network (Direct Port Forward)

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x
Download Software