我想按名称获取特定的防火墙规则,并查看它使用的选项(特别是 IP 范围)并将其与某些东西进行比较。这可能吗,我在网上搜索但找不到任何东西。
这就是我添加规则的方式:
INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
INetFwRule firewallRule = firewallPolicy.Rules.OfType<INetFwRule>().Where(x => x.Name == RULE_NAME).FirstOrDefault();
if (firewallRule == null)
{
firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
firewallRule.Name = RULE_NAME;
/* More stuff */
firewallPolicy.Rules.Add(firewallRule);
}