From 8da7714544b82665d4df7ec7d0013569ec0a60fb Mon Sep 17 00:00:00 2001 From: Tim Young Date: Mon, 20 Feb 2017 16:59:04 +0300 Subject: [PATCH] make firewall rules look nicer - add vlan to interface --- EduNetworkBuilder/FirewallEditor.cs | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/EduNetworkBuilder/FirewallEditor.cs b/EduNetworkBuilder/FirewallEditor.cs index 5d17ba3..031bc52 100644 --- a/EduNetworkBuilder/FirewallEditor.cs +++ b/EduNetworkBuilder/FirewallEditor.cs @@ -5,6 +5,7 @@ using System.Data; using System.Drawing; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; @@ -15,6 +16,7 @@ namespace EduNetworkBuilder public partial class FirewallEditor : Form { NetworkDevice FirewallDevice = null; + public FirewallEditor(NetworkDevice WhatToEdit) { InitializeComponent(); @@ -23,13 +25,42 @@ namespace EduNetworkBuilder Icon = Properties.Resources.NBIco; } + string InterfaceVLAN(string device) + { + string answer = ""; + string basedevice = Regex.Replace(device, ":.*",""); + NetworkCard nic = FirewallDevice.NicFromName(basedevice); + if (nic != null) + { + NetworkInterface nif = nic.InterfaceFromName(device); + if(nif != null) + { + Network myNet = NB.GetNetwork(); + int id = nif.GetNonForbiddenVLANID(); + foreach(VLANName vn in myNet.VlanNames) + { + if(vn.ID == id) + { + answer = vn.Name; + break; + } + } + } + } + return answer; + } + void UpdateForm() { int selected = lbRules.SelectedIndex; lbRules.Items.Clear(); foreach (FirewallRule FW in FirewallDevice.FirewallRules) { - string OneLine = FW.Action.ToString() + " " + FW.Source + " -> " + FW.Destination; + string svlan = InterfaceVLAN(FW.Source); + if (svlan != "") svlan = svlan + " "; + string dvlan = InterfaceVLAN(FW.Destination); + if (dvlan != "") dvlan = dvlan + " "; + string OneLine = FW.Action.ToString() + " " + FW.Source + " " + svlan + " -> " + FW.Destination + " " + dvlan; lbRules.Items.Add(OneLine); } if (selected >= 0 && selected < lbRules.Items.Count)