How to get user's public IP if the server is behind a router?

我与影子孤独终老i 提交于 2019-12-04 11:17:41
Anirudh Ramanathan

You are trying to deal with IP & Routing at the HTTP level.

At the Application Layer, the packet has already traversed up the Routing/IP layer and that information has been stripped out.

The packet you see at the HTTP level is exactly as sent out by the remote end-point at his Application Layer level, which was devoid of IP information, so looking in the HTTP headers won't help IMHO.

EDIT: As @Marc Gravell said, some Reverse proxies do add this information to HTTP headers. So you should check yours (if you have one configured), if it does that.

This answer lists some other server-variables you could check.

The only reliable way is to reach out to some known service on the internet that will tell you what IP it sees your request coming from. Of course, that service has to continue functioning and be reachable or this feature breaks. For example, http://whatismyip.com

There is no way of getting it.

But, you can find whether the user is opening the page from a local network or from the web.

If the IP is the IP that the router assigns to the requests coming from the web, then it's clear it comes from the web.

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