首页 > 代码库 > 获取访问IP,程序池访问,非局域网IP地址

获取访问IP,程序池访问,非局域网IP地址

 通过WebRequest类访问得到IP:

 System.Net.WebRequest wReq = System.Net.WebRequest.Create("http://ip.chinaz.com/getip.aspx");//站长工具提供Ip地址 System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding("utf-8"))) {   var json = new JavaScriptSerializer().Deserialize<ipModel>(reader.ReadToEnd());   return json.ip; }

 反序列化时用到的类:

        /// <summary>        /// IP访问返回类        /// </summary>        public class ipModel        {            public string ip { get; set; }            public string address { get; set; }        }

 注意:得到是外网IP,并非局域网IP

获取访问IP,程序池访问,非局域网IP地址