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

解决方案 »

  1.   

    找到问题了。正确的格式是这样的
    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]))$";  
      

  2.   

    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]))$";  这句后面少一个$
      

  3.   

    其实楼主看一下那个网页的返回值
    string str = System.Text.Encoding.GetEncoding("gb2312").GetString(bytRecv);
    这里str就只包含这个IP地址,没必要再用正则提取,浪费时间和资源的