会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
javawebsoa
CnBlogs
Home
New Post
Contact
Admin
通过外部网站返回得到内网外部IP
static string GetIP() { Uri uri = new Uri("http://www.ikaka.com/ip/index.asp";); System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = 0; req.CookieContainer = new System.Net.CookieContainer(); req.GetRequestStream().Write(new byte [0], 0, 0); System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)(req.GetResponse()); StreamReader rs = new StreamReader(res.GetResponseStream(), System.Text.Encoding.GetEncoding("GB18030")); string s = rs.ReadToEnd(); rs.Close(); req.Abort(); res.Close(); System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(s, @"IP:/[(?<IP>[0-9/.]*)/]"); if (m.Success) return m.Groups["IP"].Value; return string.Empty; }
posted @
2011-07-25 00:51
javawebsoa
Views(
303
) Comments(
0
)
Edit
收藏
举报
刷新页面
返回顶部
公告