Currently we are using NetFwTypeLib for adding a firewall rule to our Application, we have imported this library as a COMReference,
and we have implemented the code like this below.
public static bool AddRule(Firewall Rule){
INetFwRule firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_ALLOW;
firewallRule.Description = rule.RuleDescription;
firewallRule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN;
firewallRule.Enabled = true;
firewallRule.ApplicationName = rule.ApplicationPath;
firewallRule.RemoteAddresses = "LocalSubnet";
firewallRule.InterfaceTypes = "All";
firewallRule.Name = rule.RuleName;
INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
firewallPolicy.Rules.Add(firewallRule);
return true;
}
and its working is there any other library available in .net that can help to create a firewall rule in the Windows as well as Linux since .net standard is Platform Independent ,Could Some one please give me some suggestion to achieve this requirement.