获取IP方法
2010-11-23 10:10
176 查看
服务端:
//方法一
HttpContext.Current.Request.UserHostAddress;
//方法二
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
//方法三
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
//方法四(无视代理)
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
客户端:
//方法五
var ip = '<!--#echo var="REMOTE_ADDR"-->';
alert("Your IP address is "+ip);
//方法六(无视代理)
function GetLocalIPAddress()
if(Context.Request.ServerVariables["HTTP_VIA"]!=null) // using proxy
else// not using proxy or can't get the Client IP
备注:
1. 有些代理是不会发给我们真实IP地址的
2. 有些客户端会因为“header_access deny”的安全设置而不发给我们IP
//方法一
HttpContext.Current.Request.UserHostAddress;
//方法二
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
//方法三
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
//方法四(无视代理)
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
客户端:
//方法五
var ip = '<!--#echo var="REMOTE_ADDR"-->';
alert("Your IP address is "+ip);
//方法六(无视代理)
function GetLocalIPAddress()
if(Context.Request.ServerVariables["HTTP_VIA"]!=null) // using proxy
else// not using proxy or can't get the Client IP
备注:
1. 有些代理是不会发给我们真实IP地址的
2. 有些客户端会因为“header_access deny”的安全设置而不发给我们IP
相关文章推荐
- IOS获取自身网络信息的方法,包括自身ip,路由地址等
- Java正确获取客户端真实IP方法整理
- X-Forwarded-For 负载均衡 7 层 HTTP 模式获取来访客户端真实 IP 的方法(IIS/Apache/Nginx/Tomcat)
- C++实现获取IP、子网掩码、网关、DNS等本机网络参数的方法
- JS获取客户端IP的方法
- Android系统下获取本地IP和mac地址的方法
- C#获取本机IP的最简单方法
- web站点获取用户IP的安全方法 HTTP_X_FORWARDED_FOR检验
- 快速获取游客和用户IP的具体实现方法
- 获取用户Ip地址通用方法与常见安全隐患(HTTP_X_FORWARDED_FOR)
- C#获取IP及MAC地址的新方法
- shell获取本地ip的三种方法
- 用C#编写获取远程IP,MAC的方法
- JS获取客户端ip的方法。
- asp.net获取真实ip的方法
- windows下获取本地IP的方法
- php获取用户IP的方法
- SpringMVC中几种获取访客IP的方法
- JavaScript获取IP的方法