且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取客户端计算机的IP地址时出现问题

更新时间:2022-10-25 09:29:30

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

http:// ***。 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://***.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