how to get ip behind NAT using php?

老子叫甜甜 提交于 2019-12-17 21:59:48

问题


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.


回答1:


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




回答2:


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




回答3:


No. PHP only sees the external IP.

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




回答4:


if they are using proxy you can use

       $real_ip = $_SERVER['HTTP_X_FORWARDED_FOR']

otherwise, it is not possible




回答5:


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']


来源:https://stackoverflow.com/questions/8586812/how-to-get-ip-behind-nat-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!