public bool IsInIPRange(IPAddress ip) { if (!IsReverse) { return(_ipMatcher.Match(ip) == Rule.Direct); } return(_ipMatcher.Match(ip) == default); }
public static void TestIpMatcher(IIPAddressMatcher <Rule> tree) { tree.Update(IPAddress.Parse(@"1.0.1.0"), 28, Direct); tree.Update(IPAddress.Parse(@"1.1.1.1"), 32, Block); tree.Update(IPAddress.Parse(@"8.8.8.8"), 32, Proxy); tree.Update(IPAddress.Parse(@"192.168.0.0"), 16, Direct); tree.Update(IPAddress.Parse(@"192.168.20.16"), 28, Proxy); Assert.AreEqual(Unknown, tree.Match(IPAddress.Parse(@"10.0.0.123"))); Assert.AreEqual(Direct, tree.Match(IPAddress.Parse(@"1.0.1.0"))); Assert.AreEqual(Direct, tree.Match(IPAddress.Parse(@"1.0.1.1"))); Assert.AreEqual(Direct, tree.Match(IPAddress.Parse(@"1.0.1.15"))); Assert.AreEqual(Unknown, tree.Match(IPAddress.Parse(@"1.0.1.16"))); Assert.AreEqual(Unknown, tree.Match(IPAddress.Parse(@"1.0.1.250"))); Assert.AreEqual(Unknown, tree.Match(IPAddress.Parse(@"1.0.2.0"))); Assert.AreEqual(Block, tree.Match(IPAddress.Parse(@"1.1.1.1"))); Assert.AreEqual(Proxy, tree.Match(IPAddress.Parse(@"8.8.8.8"))); Assert.AreEqual(Direct, tree.Match(IPAddress.Parse(@"192.168.20.15"))); Assert.AreEqual(Proxy, tree.Match(IPAddress.Parse(@"192.168.20.19"))); }