internal void AddAuthorizedApplication(string strName, string processImageFileName, NetFwTypeLib.NET_FW_SCOPE_ Scope) { INetFwAuthorizedApplication authorizedApplication = (INetFwAuthorizedApplication)Activator .CreateInstance(Type.GetTypeFromProgID( "HNetCfg.FwAuthorizedApplication")); authorizedApplication.Name = strName; authorizedApplication.Scope = Scope; authorizedApplication.Enabled = true; authorizedApplication.ProcessImageFileName = processImageFileName; firewallManager.LocalPolicy.CurrentProfile .AuthorizedApplications.Add(authorizedApplication); }
internal void AddPort(string strName, int Port, NetFwTypeLib.NET_FW_SCOPE_ Scope, NetFwTypeLib.NET_FW_IP_PROTOCOL_ Protocol, string remoteAddresses) { INetFwOpenPort fireWallPort = (INetFwOpenPort)Activator.CreateInstance( Type.GetTypeFromProgID("HNetCfg.FWOpenPort")); fireWallPort.RemoteAddresses = remoteAddresses; fireWallPort.Enabled = true; fireWallPort.Name = strName; fireWallPort.Port = Port; fireWallPort.Protocol = Protocol; firewallManager.LocalPolicy.CurrentProfile .GloballyOpenPorts.Add(fireWallPort); }
internal void AddRule(string name, int port, NET_FW_IP_PROTOCOL_ protocol, NetFwTypeLib.NET_FW_RULE_DIRECTION_ direction, NetFwTypeLib.NET_FW_SCOPE_ scope, NetFwTypeLib.NET_FW_ACTION_ action, string remoteAddress) { bool ruleExists = false; string ipAddress; string ruleName = GetRuleName(name, port); INetFwRule rule = GetRule(ruleName); if (rule != null) { ruleExists = true; } else { try { rule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule", true)); } catch (Exception x) { throw x; } } if (IddsConfig.IsValidIpAddress(remoteAddress)) { ipAddress = remoteAddress; } else { throw new ArgumentOutOfRangeException("IP address must be given in IP version 4 or IP version 6 format!"); } // ipAddress = String.Format("{0}/255.255.255.255", ipAddress); if (!ruleExists) { rule.Action = action; rule.Grouping = Globals.CYBERARMS_WINDOWS_IDS_GROUP_NAME; rule.Protocol = (int)NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP; rule.Description = Globals.CYBERARMS_WINDOWS_IDS_GROUP_NAME + " rule"; rule.Direction = direction; rule.Enabled = true; if (port > 0) { rule.LocalPorts = port.ToString(); } rule.Name = ruleName; rule.RemoteAddresses = ipAddress; // rule.RemotePorts = ""; firewallPolicyManager.Rules.Add(rule); } else { rule.Enabled = true; if (rule.RemoteAddresses.Trim().Equals("*")) { rule.RemoteAddresses = ipAddress; } else { rule.RemoteAddresses = String.Format("{0},{1}", rule.RemoteAddresses, ipAddress); } } }