码迷,mamicode.com
首页 > Windows程序 > 详细

C# .net 获取外网ip

时间:2015-04-26 15:07:14      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

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

C# .net 获取外网ip

标签:

原文地址:http://www.cnblogs.com/pingming/p/4457685.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!