Snippets: SocksArmor - RulesShowAll
// SOCKSArmor Snippets - SocksArmor. // Author: Felipe Kellermann <felipek@socksarmor.org> // Revision: $Revision: 5395 $ // Date: $Date: 2008-01-03 18:05:06 -0200 (Thu, 03 Jan 2008) $ // // This snippet searches for rules containing a specific pattern and // removes every single rule found with that particular pattern. using System; using SocksArmor; class SocksArmorSnippet { static void Main(string[] args) { // Remote SOCKSArmor server. RemoteServer server = new RemoteServer(); server.Connect("127.0.0.1", 10842, "username", "password"); // Outputs the number of rules currently used in the server. Console.WriteLine("The server currently has {0} rules...", server.Rules.Count); // Counter to count the number of removed rules. int removed = 0; // RemoteServer's Rules represent a collection of filter // objects. This enumeration iterates over all the currently // available rules on the server. foreach (Rule rule in server.Rules) { if (rule.Action == RuleActions.Pass && rule.DestinationAddress == "RemoteServers") { // Outputs the rule being removed. Console.WriteLine("Rule {0} ({1}) has the pattern, removing", rule, rule.Description); // Removes the current rule from the server's rules. server.Rules.Remove(rule); // Count the bodies :-) removed++; } } // Outputs *dummy* information about the removed rules and the // remaining victims. Console.WriteLine("Removed removed: {0}", removed); Console.WriteLine("Now the server has {0} rules", server.Rules.Count); server.Disconnect(); } }
