码迷,mamicode.com
首页 > Web开发 > 详细

MVC 如何获取外网IP

时间:2014-12-19 14:11:26      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

 1 public string GetIP() 
 2 {
 3   string tempIp = "";
 4   WebRequest wr = WebRequest.Create("http://city.ip138.com/ip2city.asp");
 5   Stream s = wr.GetResponse().GetResponseStream();
 6   StreamReader sr = new StreamReader(s, Encoding.Default);
 7   string all = sr.ReadToEnd();
 8   int start = all.IndexOf("[") + 1;
 9   int end = all.IndexOf("]", start);
10   tempIp = all.Substring(start, end - start);
11   sr.Close();
12   s.Close();
13   return tempIp;
14 }

这种获取IP的方式是根据 http://city.ip138.com/ip2city.asp 来获取的,最后已截取字符串结束

MVC 如何获取外网IP

标签:

原文地址:http://www.cnblogs.com/Mr-Ray/p/4173766.html

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