简体   繁体   English

如何获取客户端系统IP地址?

[英]How to grab Client System IP Address?

I want to grab/track IP Address of Client machine(requesting machine or user's computer) not Server machine. 我想获取/跟踪客户端计算机(请求计算机或用户计算机)而不是服务器计算机的IP地址。

I have put following code to grab/track IP Address of Client machine that it's working. 我已经输入以下代码来获取/跟踪正在运行的客户端计算机的IP地址。

Request.ServerVariables.Get("REMOTE_HOST");

But it's working on those system in which internet modem directly connected with pc 但是它正在那些将互联网调制解调器直接连接到PC的系统上工作

And I need to work on those systems too in which internet modem isn't directly connected with pc (connected via router). 我还需要在那些互联网调制解调器不直接与PC连接(通过路由器连接)的系统上工作。

You can't get the internal address of the client. 您无法获取客户端的内部地址。 That's what Network Address Translation and firewalls are for. 这就是网络地址转换防火墙的用途。 I know this is a disappointing answer, but what you're asking simply isn't possible in most contexts. 我知道这是一个令人失望的答案,但是您要问的问题在大多数情况下根本不可能实现。

The only exception is if you control both the client machine and the server. 唯一的例外是如果您同时控制客户端计算机和服务器。 For example, a corporate environment. 例如,公司环境。 Then you could write some tools that would provide that information to the server. 然后,您可以编写一些工具,将这些信息提供给服务器。 Obviously, asking random people that visit your website to install your tools on their machine isn't really a feasible option. 显然,让随机访问您网站的人在您的计算机上安装您的工具并不是一个切实可行的选择。

It might help your question if you provide more detail about your environment and why you want to do this. 如果您提供有关您的环境以及为什么要这样做的更多详细信息,这可能会帮助您解决问题。

You can't really do that. 你真的不能那样做。 Also, knowing the internal network IP address is not going to help you access it in any way. 另外,知道内部网络IP地址也不会以任何方式帮助您访问它。

Try to use 'HTTP_X_CLUSTER_CLIENT_IP' OR 'HTTP_X_FORWARDED_FOR' which will return you list of comma separated IP 尝试使用“ HTTP_X_CLUSTER_CLIENT_IP”或“ HTTP_X_FORWARDED_FOR”,这将返回以逗号分隔的IP列表

i.e.    Request.ServerVariables["HTTP_X_FORWARDED_FOR"]

Thanks Suresh 谢谢苏雷什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM