文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C#获得外网的IP地址

C#获得外网的IP地址

时间:2011-03-17  来源:donqiang

1 static string GetIP()
2 {
//http://www.ip138.com/ip2city.asp
3 Uri uri = new Uri("http://www.ikaka.com/ip/index.asp");
4 System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
5 req.Method = "POST";
6 req.ContentType = "application/x-www-form-urlencoded";
7 req.ContentLength = 0;
8 req.CookieContainer = new System.Net.CookieContainer();
9 req.GetRequestStream().Write(new byte [0], 0, 0);
10 System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)(req.GetResponse());
11 StreamReader rs = new StreamReader(res.GetResponseStream(), System.Text.Encoding.GetEncoding("GB18030"));
12 string s = rs.ReadToEnd();
13 rs.Close();
14 req.Abort();
15 res.Close();
16 System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(s, @"IP:\[(?<IP>[0-9\.]*)\]");
17 if (m.Success) return m.Groups["IP"].Value;
18 return string.Empty;
19 }
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载