예제 #1
0
        /// <summary>
        /// Get all the rules currently configured with ufw
        /// </summary>
        /// <returns></returns>
        public static List <UfwRule> GetRules()
        {
            var result    = new List <UfwRule>();
            var ufwResult = LocalCommand.Execute("ufw status numbered");

            foreach (var line in ufwResult)
            {
                var rule = UfwRule.TryParse(line);;
                if (rule != null)
                {
                    result.Add(rule);
                }
            }

            return(result);
        }
예제 #2
0
 /// <summary>
 /// Enables the ufw firewall
 /// </summary>
 public static void Disable()
 {
     LocalCommand.Execute("ufw disable");
 }
예제 #3
0
 /// <summary>
 /// Enables the ufw firewall
 /// </summary>
 public static void Enable()
 {
     LocalCommand.Execute("ufw enable");
 }
예제 #4
0
 /// <summary>
 /// Deny connections from the given IP
 /// </summary>
 /// <param name="fromIP"></param>
 public static void DenyInbound(string fromIP)
 {
     LocalCommand.Execute($"ufw deny from {fromIP}");
 }
예제 #5
0
 /// <summary>
 /// Allow inbound connection from
 /// </summary>
 /// <param name="fromIP"></param>
 /// <param name="port"></param>
 public static void AllowInbound(string fromIP, int port)
 {
     Console.WriteLine($"ufw allow from {fromIP} to any port {port}");
     LocalCommand.Execute($"ufw allow from {fromIP} to any port {port}");
 }
예제 #6
0
 /// <summary>
 /// Allow inbound connections from the specific port
 /// </summary>
 /// <param name="fromIP"></param>
 /// <param name="port"></param>
 public static void AllowInbound(int port)
 {
     Console.WriteLine($"ufw allow {port}");
     LocalCommand.Execute($"ufw allow {port}");
 }
예제 #7
0
 /// <summary>
 /// Delete the rule on the given index
 /// </summary>
 /// <param name="rule"></param>
 public static void DeleteRule(UfwRule rule)
 {
     LocalCommand.Execute($"ufw --force delete {rule.RuleIndex}");
 }
예제 #8
0
        /// <summary>
        /// Returns true UFW is currently enabled
        /// </summary>
        /// <returns></returns>
        public static bool IsEnabled()
        {
            var ufwResult = LocalCommand.Execute("ufw status numbered");

            return(ufwResult.Where(e => e.Contains("Status: active")).FirstOrDefault() != null);
        }