查找客户端/用户计算机的IP地址 [英] Find ip address of client/user machine

查看:124
本文介绍了查找客户端/用户计算机的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net mvc中有一个web api。在Post请求,我想获得客户端/用户的机器的IP地址。我试过以下代码,但获取服务器的IP地址。请帮助



我尝试过:



I have a web api in asp.net mvc. On Post request, i want to get ip address of client's/users's machine. I have tried following code,but getting the ip address of server. Please help

What I have tried:

HttpContext.Current.Request.UserHostAddress;










string ip5 = HttpContext.Current.Request.Params["HTTP_CLIENT_IP"] ?? HttpContext.Current.Request.UserHostAddress;













ip7 = HttpContext.Current.Request.UrlReferrer.ToString();










string ip10 = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
              if (ip10 != null || ip10 != String.Empty)
              {
                  ip10 = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
              }

推荐答案

您好:

我正在使用
Hello:
I´m using
HttpContext.Current.Request.UserHostAddress;

在我的应用程序中,它运行正常。

也许在您处理帖子的代码中,您指定了更多的地方客户机的ip。断点并检查HttpContext.Current.Request.UserHostAddress的值可以帮助你。

in my application and it works ok.
Perhaps in the code where you process the post there are more places where you assign the ip of the machine of the client. A breakpoint and exam the value of HttpContext.Current.Request.UserHostAddress could help you.


这是一个非常常见的问题,如果你在发布之前用Google搜索,你会发现答案您无法获取客户端计算机的IP,只能获取请求来自的计算机(例如代理服务器)。如果您使用的代码正在返回服务器IP,那么您的设置就不会告诉我们,例如服务器充当客户端的代理。
This is a very frequently asked question and if you googled it before posting you would have found the answer that you can't get the IP of the client machine, only the machine the request came from (so a proxy server for example). If the code you are using is returning the server IP then there is something about your set-up you're not telling us such as the server acting as a proxy to the clients.


这篇关于查找客户端/用户计算机的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆