public static String GetIP() { String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(ip)) { ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } return ip; }
Java的api的说法: getHeader public java.lang.String getHeader(java.lang.String name) Return the first value of the specified header, if any; otherwise, return null 返回指定标头的第一个值(如果有的话):否则返回null. Specified by: getHeader in interface javax.servlet.http.HttpSe
背景:博主本是一位Windows桌面应用程序开发工程师,对网络通信一知半解.一日老婆逛完某宝,问:"为什么他们知道我的地址呢,他们是怎么获取我的地址的呢?" 顺着这个问题我们的探秘开始: 第一步:简单的服务搭建 思路,通过HttpListener在本地搭建一个简易的服务器,开发程序为控制台接口,核心类 HttpListenerService: 方法 Start()开启线程池针对指定IP进行监听,本地的端口选取的9527(周星驰唐伯虎点秋香在华府的编号) public void Star
最近web获取客户端ip,看到下面这篇文章,转载过来,一起分享(转载地址:http://www.cnblogs.com/yejun/archive/2008/02/26/1082485.html) 通常我们都通过下面的代码获得IP: string ip =System.Web.HttpContext.Current.Request.UserHostAddress; 或 string ip =System.Web.HttpContext.Current.Request.ServerVariable