public bool AccessPermitted(string IpAddress)
{
// If no restriction exists, return TRUE
if ((RestrictionRanges == null) || (RestrictionRanges.Count == 0))
return true;
// Was the comparison set built?
if (rangeTester == null)
{
rangeTester = new IpRangeSetV4();
foreach (Engine_RestrictionRange thisRangeSet in RestrictionRanges)
{
foreach (Engine_IpRange thisRange in thisRangeSet.IpRanges)
{
if (!String.IsNullOrEmpty(thisRange.EndIp))
rangeTester.AddIpRange(thisRange.StartIp, thisRange.EndIp);
else
rangeTester.AddIpRange(thisRange.StartIp);
}
}
}
// You can always acess from the same machine (first may only be relevant in Visual Studio while debugging)
if ((IpAddress == "::1") || (IpAddress == "127.0.0.1"))
return true;
// Now, test the IP against the tester
return rangeTester.Contains(new ComparableIpAddress(IpAddress));
}