WebClient client = new WebClient();
byte[] bytRecv = client.DownloadData("http://www.eyesoft.com.cn/ip.asp"); //下載數據
string str = System.Text.Encoding.GetEncoding("gb2312").GetString(bytRecv);
string r = @"(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))";
string ip = System.Text.RegularExpressions.Regex.Match(str, r).ToString(); //提取信息
this.label6.Text = ip.ToString();我获取的IP是60.222.148.12而真实的IP是60.222.148.127
byte[] bytRecv = client.DownloadData("http://www.eyesoft.com.cn/ip.asp"); //下載數據
string str = System.Text.Encoding.GetEncoding("gb2312").GetString(bytRecv);
string r = @"(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))";
string ip = System.Text.RegularExpressions.Regex.Match(str, r).ToString(); //提取信息
this.label6.Text = ip.ToString();我获取的IP是60.222.148.12而真实的IP是60.222.148.127
string r = @"(((\d{1,2}) ¦(1\d{2}) ¦(2[0-4]\d) ¦(25[0-5]))\.){3}((\d{1,2}) ¦(1\d{2}) ¦(2[0-4]\d) ¦(25[0-5]))$";
string str = System.Text.Encoding.GetEncoding("gb2312").GetString(bytRecv);
这里str就只包含这个IP地址,没必要再用正则提取,浪费时间和资源的