/// <summary> /// 分割字符串 /// </summary> public static string[] SplitString(string strContent, string strSplit) { if (!ValidatorHelper.IsNullOrEmptyString(strContent)) { if (strContent.IndexOf(strSplit) < 0) { string[] tmp = { strContent }; return(tmp); } return(Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase)); } else { return(new string[0] { }); } }
/// <summary> /// 返回指定IP是否在指定的IP数组所限定的范围内, IP数组内的IP地址可以使用*表示该IP段任意, 例如192.168.1.* /// </summary> /// <param name="ip"></param> /// <param name="iparray"></param> /// <returns></returns> public static bool InIPArray(string ip, string[] iparray) { string[] userip = ValidatorHelper.SplitString(ip, @"."); for (int ipIndex = 0; ipIndex < iparray.Length; ipIndex++) { string[] tmpip = ValidatorHelper.SplitString(iparray[ipIndex], @"."); int r = 0; for (int i = 0; i < tmpip.Length; i++) { if (tmpip[i] == "*") { return(true); } if (userip.Length > i) { if (tmpip[i] == userip[i]) { r++; } else { break; } } else { break; } } if (r == 4) { return(true); } } return(false); }