在ASP.NET中获取客户端IP [英] get Client IP in ASP.NET
问题描述
我想使用代理服务器(ISA Server)从Web浏览器获取客户端IP,我使用 Request.ServerVariables["REMOTE_HOST"]
或Request.ServerVariables["REMOTE_ADDR"]
始终返回服务器ISA Server的IP.
例如:我的计算机具有静态IP 10.1.164.68,并且ISA Server的IP为192.168.1.50,并且在浏览器中声明通过ISA Server连接到Internet,当我使用Request.ServerVariables["REMOTE_HOST"]
或Request.ServerVariables["REMOTE_ADDR"]
时,它始终返回IP 192.168.1.50.如何获取我的计算机的真实IP(IP:10.1.164.68).
感谢您的阅读.
Kevin Ho
I want get client IP from web browser using Proxy (ISA Server), I using Request.ServerVariables["REMOTE_HOST"]
or Request.ServerVariables["REMOTE_ADDR"]
alway return IP of server ISA Server.
ex: My Computer have Static IP 10.1.164.68 and IP of ISA Server is 192.168.1.50, and in Browser declare connect to Internet through ISA Server, when I using Request.ServerVariables["REMOTE_HOST"]
or Request.ServerVariables["REMOTE_ADDR"]
Its always return IP 192.168.1.50. How can I get real IP of My Computer (IP:10.1.164.68).
Thanks for reading.
Kevin Ho
推荐答案
获得Internet IP地址的唯一方法是访问您本地网络之外的站点:即,在Internet上.
如果Request.ServerVariables告诉您IP地址为192.168.xx,则这很好地表明服务器和客户端都在同一本地网络上(路由器通常将192.168.xx分配给内部计算机).
如果服务器和客户端中的一个或另一个在网络外部,则Internet IP地址可用.
The only way to get the internet IP address is to access a site that is outside your local network: i.e. on the internet.
If Request.ServerVariables is telling you that the IP address is 192.168.x.x then that is a good indication that both the server and the client are on the same local network (192.168.x.x is generally allocated by routers to internal computers).
If one or other of the server and client is outside the network, then the internet IP address is available.
嗨
这是获取IP地址的代码
hi
here is the code to get ip address
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
string ipadd = localIPs[0].ToString();
这会帮助你
this will help u
这篇关于在ASP.NET中获取客户端IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!