Can we use some .net standrd 2.0 library that can work on both Windows and Linux for adding a firewall rule ?

Aditya Dalai 20 Reputation points
2023-10-20T06:46:18.06+00:00

Currently we are using NetFwTypeLib for adding a firewall rule to our Application, we have imported this library as a COMReference,

User's image

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.

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,776 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,402 questions
Microsoft Intune Linux
Microsoft Intune Linux
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Linux: A family of open-source Unix-like operating systems.
42 questions
0 comments No comments
{count} votes