获取客户端计算机的IP地址时出现问题 [英] Problem in getting IP Address of client machine

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

问题描述

大家好,



我必须获取ip地址客户端机器。

为此我使用以下代码:

 受保护  void  Application_BeginRequest( object  sender,EventArgs e)
{
HttpRequest request = .Request;
string address = request.UserHostAddress;
base .Response.Write(address);
}





我的IP地址是202.164.45.14

但是当我运行上面的代码时在我的本地系统上,它返回:: 1

当我在我的内部服务器上部署它时,它给出192.168.3.1



我还试过了

 HttpRequest.ServerVariables [REMOTE_ADDR] 





但它也结果相同。



谢谢,

Richa Sharma

解决方案

参见如果以下讨论可以帮助您:

http:// stackoverflow。 com / questions / 2670004 / ip-address-of-the-client-machine [ ^ ]

如何在asp.net(C#)中获取客户端IP。 [ ^ ]

客户端计算机IP地址 [ ^ ]


:: 1 您的地址。正如127.0.0.1是IPv4中的环回地址一样,:: 1是IPv6上的环回

请参阅 Localhost [ ^ ]

除非你需要一个正确解析的IP,否则我会保留你的代码,一旦它从网络上的另一台机器上测试过。


感谢大家对这个问题感兴趣。

但问题是防火墙。当我在服务器上部署它时,它工作正常。





谢谢,

Richa Sharma

Hi All,

I have to fetch the ip address client machine.
for this i use the below code:

protected void Application_BeginRequest(object sender, EventArgs e)
   {
       HttpRequest request = base.Request;
       string address = request.UserHostAddress;
       base.Response.Write(address);
   }



My Ip Address is 202.164.45.14
But when i run the above code on my local system, it returns ::1
And when i deploy it on my internal server it is giving 192.168.3.1

I also tried

HttpRequest.ServerVariables["REMOTE_ADDR"]



but it also gave same result.

Thanks,
Richa Sharma

解决方案

See if following discussions help you:
http://stackoverflow.com/questions/2670004/ip-address-of-the-client-machine[^]
How to get client IP in asp.net(C#).[^]
client machines ip address[^]


::1 is your address. Just as 127.0.0.1 is the loopback address in IPv4, ::1 is the loopback on IPv6
see Localhost[^]
Unless you need a "properly" resolved IP I'd keep your code, once it had been tested from another machine on the network.


Thanks all for your interest in this question.
But the problem is firewalls. When i deploy this on server, it is working fine.


Thanks,
Richa Sharma


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

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