比如我有如下ip列表:192.168.4.*, 218.102.*.*, 192.168.5.10
*代表任意数字。
假设我传递一个ip是192.168.4.37,因为包含在列表里面,所以匹配成功。
假设我传递一个ip是192.168.5.37,因为包含在列表里面,所以匹配不成功。
假设我传递一个ip是218.102.5.21,因为包含在列表里面,所以匹配不成功。
thanks in advance.

解决方案 »

  1.   

     
        private int ReturnIP(string ip)
        {
            string[] scIP = ip.Split('.');
            int ipSplit = Convert.ToInt32(scIP[0]) * 256 * 256 * 256 + Convert.ToInt32(scIP[1]) * 256 * 256 + Convert.ToInt32(scIP[2]) * 256 + Convert.ToInt32(scIP[3]);
            return ipSplit;
        }
    这个是c#里面的代码,把ip转换为int类型的,然后进行比较匹配
      

  2.   

    Regex reg=new Regex("192.168.4.*");
    return reg.IsMatch(str);