Ejemplo n.º 1
0
        private static uint FindLowestAllowedIP(List <BlockedIPRange> blockedIPRanges)
        {
            uint highestEnd = blockedIPRanges[0].GetEnd();

            for (int i = 0; i < blockedIPRanges.Count - 1; i++)
            {
                BlockedIPRange range     = blockedIPRanges[i];
                BlockedIPRange nextRange = blockedIPRanges[i + 1];

                if (range.GetEnd() > highestEnd)
                {
                    highestEnd = range.GetEnd();
                }

                if (nextRange.GetStart() > highestEnd + 1)
                {
                    return(highestEnd + 1);
                }
            }

            throw new Exception("All IPs are blocked. Sorry");
        }
Ejemplo n.º 2
0
        private static uint FindNumAllowedIPs(List <BlockedIPRange> blockedIPRanges)
        {
            uint numAllowedIPs = 0;
            uint highestEnd    = blockedIPRanges[0].GetEnd();

            for (int i = 0; i < blockedIPRanges.Count - 1; i++)
            {
                BlockedIPRange range     = blockedIPRanges[i];
                BlockedIPRange nextRange = blockedIPRanges[i + 1];

                if (range.GetEnd() > highestEnd)
                {
                    highestEnd = range.GetEnd();
                }

                if (nextRange.GetStart() - 1 > highestEnd)
                {
                    numAllowedIPs += nextRange.GetStart() - highestEnd - 1;
                    highestEnd     = nextRange.GetEnd();
                }
            }

            return(numAllowedIPs);
        }