返回本机的外网ip地址

 public static string GetIP()
        {
            string strUrl = "http://www.ip138.com/ip2city.asp"//获得IP的网址了
            Uri uri = new Uri(strUrl);
            WebRequest wr = WebRequest.Create(uri);
            Stream s = wr.GetResponse().GetResponseStream();
            StreamReader sr = new StreamReader(s, Encoding.Default);
            string all = sr.ReadToEnd(); //读取网站的数据
            int i = all.IndexOf("[") + 1;
            string tempip = all.Substring(i, 15);
            string ip = tempip.Replace("]""").Replace(" """);
            return ip;
        }
posted @ 2014-11-10 10:33  You最温暖的港湾  阅读(575)  评论(0)    收藏  举报