private bool TestBlockAllInboundTraffic(bool Block) { if (mFirewallPolicy.get_BlockAllInboundTraffic(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE) != Block) { return(false); } if (mFirewallPolicy.get_BlockAllInboundTraffic(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN) != Block) { return(false); } if (mFirewallPolicy.get_BlockAllInboundTraffic(NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC) != Block) { return(false); } return(true); }
/* Returns default inbound action (Block|Allow) for profile */ public String getCurInboundAction(NET_FW_PROFILE_TYPE2_ profile) { var curAction = "None"; var curActions = new List <string>(); var tmpstr = ""; var fwProfiles = Enum.GetValues(typeof(NET_FW_PROFILE_TYPE2_)); updateCurrentProfile(); foreach (NET_FW_PROFILE_TYPE2_ fwProfile in fwProfiles) { if ((profile & fwProfile) == fwProfile) { tmpstr = getActionName(fw.get_DefaultInboundAction(fwProfile)); if (fw.get_BlockAllInboundTraffic(fwProfile) == true) { tmpstr = tmpstr + " (All)"; } curActions.Add(tmpstr); } } if (curActions.Count > 0) { curAction = String.Join(",", curActions); } return(curAction); }
static void publicFirewall() { Type netFwPolicy2Type = Type.GetTypeFromProgID("HNetCfg.FwPolicy2"); INetFwPolicy2 mgr = (INetFwPolicy2)Activator.CreateInstance(netFwPolicy2Type); NET_FW_PROFILE_TYPE2_ fwPublicProfileType = NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC; Console.WriteLine("Public Profile Type:"); var firewallEnabled = mgr.get_FirewallEnabled(fwPublicProfileType); var blockAllInboundTraffic = mgr.get_BlockAllInboundTraffic(fwPublicProfileType); var defaultInboundAction = mgr.get_DefaultInboundAction(fwPublicProfileType); var defaultOutboundAction = mgr.get_DefaultOutboundAction(fwPublicProfileType); Console.WriteLine($"Firewall Enabled: {firewallEnabled.ToString()}"); Console.WriteLine($"Block All Inbound Traffic: {blockAllInboundTraffic.ToString()}"); Console.WriteLine($"Default Inbound Action:{defaultInboundAction.ToString()}"); Console.WriteLine($"Default Outbound Action:{defaultOutboundAction.ToString()}"); }
public bool GetBlockAllInboundTraffic(FirewallRule.Profiles profileType) { return(NetFwPolicy.get_BlockAllInboundTraffic((NET_FW_PROFILE_TYPE2_)profileType)); }