首页 > Windows开发 > 详细

C# .net 获取外网ip

时间:2015-04-26 15:06:57      阅读:284      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!