Ejemplo n.º 1
0
        /// <summary>
        /// Ip地址段是否包含另外一个IP地址
        /// </summary>
        /// <param name="rule"></param>
        /// <param name="clientIp"></param>
        /// <returns></returns>
        public static bool ContainsIp(string rule, string clientIp)
        {
            var ip = ParseIp(clientIp);

            var range = new IpAddressRange(rule);

            if (range.Contains(ip))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ip地址集合是否包含另外一个IP地址
        /// </summary>
        /// <param name="ipRules">Ip地址集合List</param>
        /// <param name="clientIp"></param>
        /// <returns></returns>
        public static bool ContainsIp(List <string> ipRules, string clientIp)
        {
            var ip = ParseIp(clientIp);

            if (ipRules != null && ipRules.Any())
            {
                foreach (var rule in ipRules)
                {
                    var range = new IpAddressRange(rule);
                    if (range.Contains(ip))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }