How to get router static ip?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joinnavdev
Forum Newbie
Posts: 21
Joined: Thu Feb 05, 2015 2:34 pm

How to get router static ip?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to get router static ip?

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: How to get router static ip?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to get router static ip?

Post 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"]);
Post Reply