public override Task <bool> BlockIPAddresses(string ruleNamePrefix, IEnumerable <string> ipAddresses, IEnumerable <PortRange> allowedPorts = null, CancellationToken cancelToken = default) { IEnumerable <string> ipv4 = ipAddresses.Where(i => IPAddress.TryParse(i, out IPAddress obj) && obj.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); IEnumerable <string> ipv6 = ipAddresses.Where(i => IPAddress.TryParse(i, out IPAddress obj) && obj.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6); bool result = base.BlockIPAddresses(ruleNamePrefix, ipv4, allowedPorts, cancelToken).Sync(); if (result) { result = firewall6.BlockIPAddresses(ruleNamePrefix, ipv6, allowedPorts, cancelToken).Sync(); } return(Task.FromResult(result)); }
public async Task <bool> BlockIPAddresses(string ruleNamePrefix, IEnumerable <string> ipAddresses, CancellationToken cancelToken = default) { bool result = await firewall6.BlockIPAddresses(ruleNamePrefix, ipAddresses, cancelToken); if (!result) { return(false); } try { string ruleName = (string.IsNullOrWhiteSpace(ruleNamePrefix) ? BlockRuleName : RulePrefix + ruleNamePrefix); bannedIPAddresses = UpdateRule(ruleName, "DROP", ipAddresses, bannedIPAddresses, "ip", blockRuleMaxCount, false, null, cancelToken, out result); return(result); } catch (Exception ex) { IPBanLog.Error(ex); return(false); } }