public bool Contains(System.Net.IPAddress ipAddressObj, int port) { if (ipAddressObj.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { return(Contains(ipAddressObj.ToUInt32(), port)); } return(Contains(ipAddressObj.ToUInt128(), port)); }
public bool Contains(System.Net.IPAddress ipAddressObj) { if (ipAddressObj.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { return(ipv4.Contains(ipAddressObj.ToUInt32())); } return(ipv6.Contains(ipAddressObj.ToUInt128())); }
public bool IsIPAddressBlocked(System.Net.IPAddress ipAddressObj, out string ruleName, int port = -1) { lock (this) { if (IsIPAddressAllowed(ipAddressObj, out ruleName, port)) { return(false); } else if (ipAddressObj.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { uint ipv4 = ipAddressObj.ToUInt32(); foreach (KeyValuePair <string, MemoryFirewallRule> rule in blockRules) { if (rule.Value.Contains(ipv4)) { ruleName = rule.Key; return(true); } } foreach (KeyValuePair <string, MemoryFirewallRuleRanges> rule in blockRulesRanges) { if (rule.Value.Contains(ipv4, port)) { ruleName = rule.Key; return(true); } } } else { UInt128 ipv6 = ipAddressObj.ToUInt128(); foreach (KeyValuePair <string, MemoryFirewallRule> rule in blockRules) { if (rule.Value.Contains(ipv6)) { ruleName = rule.Key; return(true); } } foreach (KeyValuePair <string, MemoryFirewallRuleRanges> rule in blockRulesRanges) { if (rule.Value.Contains(ipv6, port)) { ruleName = rule.Key; return(true); } } } } ruleName = null; return(false); }