Page 1 of 1

How to get router static ip?

Posted: Wed Jul 01, 2015 9:39 am
by joinnavdev
Hi All,

Looking for help in resolving the below issue.......

Through router(static ip) we are forwarding the request to internal system which is in LAN & the issue is how to get the static ip as when we try $_SERVER['SERVER_ADDR']; we get LAN IP as output & not static ip?

Thanks,
Nick

Re: How to get router static ip?

Posted: Wed Jul 01, 2015 2:18 pm
by requinix

Code: Select all

+----------+                          +--------+                                +-----+
| internet | 11.22.33.44 ---> 9.8.7.6 | router | 192.168.0.1 ---> 192.168.0.100 | PHP |
+----------+                          +--------+                                +-----+
- 11.22.33.44 is the IP address of your visitor. You cannot get this address unless you set up your router as an actual HTTP proxy and not just as a router.
- 9.8.7.6 is the router's static IP address. You cannot get this without querying (a) the router itself if it has something to tell you that or (b) an external "what is my IP address"-type service.
- 192.168.0.1 is the router's LAN IP address. This will be the REMOTE_ADDR.
- 192.168.0.100 is your PHP server's IP address. This will be the SERVER_ADDR.

Re: How to get router static ip?

Posted: Thu Jul 02, 2015 3:28 pm
by Weirdan
requinix wrote: - 11.22.33.44 is the IP address of your visitor. You cannot get this address unless you set up your router as an actual HTTP proxy and not just as a router.
[...]
- 192.168.0.1 is the router's LAN IP address. This will be the REMOTE_ADDR.
You confused SNAT (source ip address translation, the thing that you described) with DNAT (destination address translation, which has to be used here).

Regardless, answering original question:
I'd suggest either:
a) put the external ip into a config file and let the administrator of that webservice specify it; or
b) automate option a) by querying some external service

Re: How to get router static ip?

Posted: Thu Jul 02, 2015 3:52 pm
by requinix
Weirdan wrote:
requinix wrote: - 11.22.33.44 is the IP address of your visitor. You cannot get this address unless you set up your router as an actual HTTP proxy and not just as a router.
[...]
- 192.168.0.1 is the router's LAN IP address. This will be the REMOTE_ADDR.
You confused SNAT (source ip address translation, the thing that you described) with DNAT (destination address translation, which has to be used here).
Ah, I was conflicted and thinking of two things at once. I'll try again:

11.22.33.44 will be the REMOTE_ADDR, unless the router intercepted the traffic (eg, SSL termination) in which case it's proxying and should have sent an X-Forwarded-For.

Code: Select all

$remote_addr = (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]);