62,271
社区成员
发帖
与我相关
我的任务
分享
public string netIP()
{
Uri uri = new Uri("http://www.ikaka.com/ip/index.asp");//查本机网络IP的网页
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = 0;
req.CookieContainer = new CookieContainer();
req.GetRequestStream().Write(new byte[0], 0, 0);
HttpWebResponse res = (HttpWebResponse)(req.GetResponse());
StreamReader rs = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("GB2312"));
string s = rs.ReadToEnd();
rs.Close();
req.Abort();
res.Close();
Match m = Regex.Match(s, @"IP:\[(?<IP>[0-9\.]*)\]");
if (m.Success) return m.Groups["IP"].Value;
string strnetIP = string.Empty;
return strnetIP;
}