Exemple #1
0
        /* 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);
        }
Exemple #2
0
 public FirewallRule.Actions GetDefaultInboundAction(FirewallRule.Profiles profileType)
 {
     if (NetFwPolicy.get_DefaultInboundAction((NET_FW_PROFILE_TYPE2_)profileType) == NET_FW_ACTION_.NET_FW_ACTION_BLOCK)
     {
         return(FirewallRule.Actions.Block);
     }
     return(FirewallRule.Actions.Allow);
 }
        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()}");
        }