how to get ip behind NAT using php?

2019-02-23 01:09发布

Is it possible to retrieve IP behind NAT in PHP? I am using $_SERVER["REMOTE_ADDR"] for getting IP address of the client. It's not giving exact IP address of the client which is in behind NAT.

标签: php wamp lamp
5条回答
The star\"
2楼-- · 2019-02-23 01:35

You cannot see the private address of client and usually you don't care to see it beacuse you can't access that. Even if it used a proxy, sometimes you may get address by:

 $_SERVER['HTTP_X_FORWARDED_FOR']
查看更多
走好不送
3楼-- · 2019-02-23 01:39

Nope, not possible. NAT means Network Address Translation - the IP address of the packets is rewritten at the NAT device, so the public IP address is the only one, as far as your server knows.

However, you can employ some tricks - such as checking for the internal IP address using a Java Applet. See this: Get the correct local IP address from java applet

查看更多
混吃等死
4楼-- · 2019-02-23 01:45

It is not possible to get the IP behind a NAT using HTTP and php.

查看更多
男人必须洒脱
5楼-- · 2019-02-23 01:46

if they are using proxy you can use

       $real_ip = $_SERVER['HTTP_X_FORWARDED_FOR']

otherwise, it is not possible

查看更多
闹够了就滚
6楼-- · 2019-02-23 01:50

No. PHP only sees the external IP.

'REMOTE_ADDR' The IP address from which the user is viewing the current page.

查看更多
登录 后发表回答