/// <summary> /// 获取规则 /// </summary> /// <returns></returns> public List <FirewallItem> GetRule() { string xml = UserManager.BasePath + "\\firewallRule.xml"; XmlDocument doc = new XmlDocument(); doc.Load(xml); XmlNodeList lstRule = doc.GetElementsByTagName("rule"); List <FirewallItem> lstRet = new List <FirewallItem>(); string name = null; string ruleName = null; string rulePath = null; string remotePorts = null; string localPorts = null; string direction = null; foreach (XmlNode node in lstRule) { XmlAttribute att = node.Attributes["name"]; name = att.InnerText; att = node.Attributes["ruleName"]; ruleName = att.InnerText; att = node.Attributes["rulePath"]; rulePath = att.InnerText; att = node.Attributes["remotePorts"]; remotePorts = att.InnerText; att = node.Attributes["localPorts"]; localPorts = att.InnerText; att = node.Attributes["direction"]; direction = att.InnerText; IList <INetFwRule2> netrule = WinFirewallUnit.FindRule(ruleName, rulePath, remotePorts, localPorts, direction); if (netrule == null || netrule.Count <= 0) { if (ShowError) { LogError("找不到规则:" + name); } } FirewallItem item = new FirewallItem(); item.Name = name; item.Rule = netrule; lstRet.Add(item); } return(lstRet); }
/// <summary> /// 获取规则 /// </summary> /// <returns></returns> public static List <FirewallItem> GetRule() { string xml = CommonMethods.GetBaseRoot("App_Data/firewallRule.xml"); XmlDocument doc = new XmlDocument(); doc.Load(xml); XmlNodeList lstRule = doc.GetElementsByTagName("rule"); List <FirewallItem> lstRet = new List <FirewallItem>(); string name = null; string ruleName = null; string port = null; string protocol = null; string[] arrProtocol = null; foreach (XmlNode node in lstRule) { XmlAttribute att = node.Attributes["name"]; name = att.InnerText; att = node.Attributes["port"]; port = att.InnerText; att = node.Attributes["protocol"]; protocol = att.InnerText; if (string.IsNullOrWhiteSpace(protocol)) { protocol = "tcp"; } arrProtocol = protocol.Split(','); foreach (string sProtocol in arrProtocol) { if (string.IsNullOrWhiteSpace(sProtocol)) { continue; } FirewallItem item = new FirewallItem(); item.Name = name; item.Port = port.ConvertTo <int>(); item.Protocol = sProtocol; lstRet.Add(item); } } return(lstRet); }
private static int CalculateSeverity(FirewallItem firewallItem, int pointInTime, Func <FirewallItem, int> scoreFunc) { if (firewallItem == null) { return(0); } var index = pointInTime; var doubleRange = firewallItem.Range * 2 - 2; var doublePosition = index % doubleRange; var position = doublePosition < firewallItem.Range ? doublePosition : doubleRange - doublePosition; return(position == 0 ? scoreFunc(firewallItem) : 0); }