Beispiel #1
0
        private static void AddRule(string appName, string ruleName)
        {
            var commandIn  = $"{FirewallCmd} add rule name=\"{ruleName}\" dir=in action=allow program=\"{appName}\"";
            var commandOut = $"{FirewallCmd} add rule name=\"{ruleName}\" dir=out action=allow program=\"{appName}\"";

            CmdRunner.Execute(commandIn);
            CmdRunner.Execute(commandOut);
        }
Beispiel #2
0
        private static void RemoveRule(string appName, string ruleName)
        {
            var commandIn  = $"{FirewallCmd} delete rule name=\"{ruleName}\" dir=in program=\"{appName}\"";
            var commandOut = $"{FirewallCmd} delete rule name=\"{ruleName}\" dir=out program=\"{appName}\"";

            CmdRunner.Execute(commandIn);
            CmdRunner.Execute(commandOut);
        }
Beispiel #3
0
        /// <summary>
        /// Determines whether the firewall exception of the specified program file exists.
        /// </summary>
        /// <param name="fileName">The full path of the specified program file.</param>
        /// <returns></returns>
        public static bool ExceptionExists(string fileName)
        {
            var nameWithEx = Path.GetFileName(fileName);

            var cmd    = $"{FirewallCmd} show rule name ={nameWithEx} verbose";
            var output = CmdRunner.ExecuteWithOutput(cmd);

            if (!string.IsNullOrEmpty(output))
            {
                if (output.Contains(fileName))
                {
                    return(true);
                }
            }

            return(false);
        }