获取公网IP

        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;
        }

  

posted on 2016-10-08 15:53  路人甲zzz  阅读(262)  评论(0编辑  收藏  举报

导航