首页 > 其他 > 详细

获取公网IP

时间:2016-10-08 16:31:18      阅读:240      评论:0      收藏:0      [点我收藏+]
        private static string GetIP()
        {
            string tempip = "";
            try
            {
                WebRequest wr = WebRequest.Create("http://ip.myhostadmin.net/");
                Stream s = wr.GetResponse().GetResponseStream();
                StreamReader sr = new StreamReader(s, Encoding.Default);
                string all = sr.ReadToEnd(); //读取网站的数据

                all = all.Replace("class=\"STYLE1\">", "*");
                all = all.Replace("</h1>", "&");
                int start = all.IndexOf("*") + 1;
                int end = all.LastIndexOf("&");
                tempip = all.Substring(start, end - start);
                sr.Close();
                s.Close();
            }
            catch
            {
            }
            return tempip;
        }

  

获取公网IP

原文:http://www.cnblogs.com/hz1234/p/5939026.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!