Esempio n. 1
0
 public void ReselectNIC(ComboBox box)
 {
     foreach (Object objnic in box.Items)
     {
         NIC nic = (NIC)objnic;
         if (nic.Name.Equals(this.Name))
         {
             box.SelectedItem = objnic;
         }
     }
 }
Esempio n. 2
0
        private void btnSetDHCP_Click(object sender, EventArgs e)
        {
            try
            {
                NIC nic = (NIC)this.comboAdapterList.SelectedItem;

                nic.SetDHCP();
                NIC.LoadNICs(this.comboAdapterList);
                nic.ReselectNIC(this.comboAdapterList);

                nic = (NIC)this.comboAdapterList.SelectedItem;
                FormHandler.UpdateNICText(nic, this.txtAdapterIPAddress, this.txtAdapterSubnetMask, this.txtAdapterDefaultGateway);
            }
            catch (Exception ex)
            {
                Logger.WriteMessage("Error in setting DHCP.");
                Logger.WriteException(ex);
                Logger.PromptLogReview("There was an error in setting DHCP.");
            }
        }
Esempio n. 3
0
        public static void LoadNICs(ComboBox box)
        {
            box.Items.Clear();

            /** Scan through each NIC interface **/
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                /** Verify it suport IPv4, is operating, and is not a loopback **/
                if (nic.Supports(NetworkInterfaceComponent.IPv4) && nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                {
                    NIC newNic = new NIC();
                    StaticIP ip = new StaticIP();

                    newNic.Name = nic.Name;
                    newNic.DHCPEnabled = nic.GetIPProperties().GetIPv4Properties().IsDhcpEnabled;

                    /** We assume the last result is the IPv4 address **/
                    UnicastIPAddressInformation uni = nic.GetIPProperties().UnicastAddresses.LastOrDefault();
                    if (uni != null)
                    {
                        ip.Address = uni.Address.ToString();
                        ip.SubnetMask = uni.IPv4Mask.ToString();
                    }

                    /** We assume the first gateway address is the default one **/
                    GatewayIPAddressInformation gate = nic.GetIPProperties().GatewayAddresses.FirstOrDefault();
                    if (gate != null)
                    {
                        ip.DefaultGateway = gate.Address.ToString();
                    }

                    newNic.IP = ip;
                    box.Items.Add(newNic);
                }
            }

            if (box.Items.Count > 0)
            {
                box.SelectedIndex = 0;
            }
        }
Esempio n. 4
0
        public static void LoadNICs(ComboBox box)
        {
            box.Items.Clear();

            /** Scan through each NIC interface **/
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                /** Verify it suport IPv4, is operating, and is not a loopback **/
                if (nic.Supports(NetworkInterfaceComponent.IPv4) && nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                {
                    NIC      newNic = new NIC();
                    StaticIP ip     = new StaticIP();

                    newNic.Name        = nic.Name;
                    newNic.DHCPEnabled = nic.GetIPProperties().GetIPv4Properties().IsDhcpEnabled;

                    /** We assume the last result is the IPv4 address **/
                    UnicastIPAddressInformation uni = nic.GetIPProperties().UnicastAddresses.LastOrDefault();
                    if (uni != null)
                    {
                        ip.Address    = uni.Address.ToString();
                        ip.SubnetMask = uni.IPv4Mask.ToString();
                    }

                    /** We assume the first gateway address is the default one **/
                    GatewayIPAddressInformation gate = nic.GetIPProperties().GatewayAddresses.FirstOrDefault();
                    if (gate != null)
                    {
                        ip.DefaultGateway = gate.Address.ToString();
                    }

                    newNic.IP = ip;
                    box.Items.Add(newNic);
                }
            }

            if (box.Items.Count > 0)
            {
                box.SelectedIndex = 0;
            }
        }
Esempio n. 5
0
        private void btnSetStatic_Click(object sender, EventArgs e)
        {
            if (this.treeSites.SelectedNode == null)
            {
                MessageBox.Show("Please select an NAE to set a static IP for.");
                return;
            }

            if (!(this.treeSites.SelectedNode.Tag is NAE))
            {
                MessageBox.Show("Please select an NAE to set a static IP for.");
                return;
            }

            try
            {
                NAE nae = (NAE)this.treeSites.SelectedNode.Tag;
                NIC nic = (NIC)this.comboAdapterList.SelectedItem;

                if (!StaticIP.IsIPv4(nae.StaticIPAddress.Address) || !StaticIP.IsIPv4(nae.StaticIPAddress.SubnetMask) || !StaticIP.IsIPv4(nae.StaticIPAddress.DefaultGateway))
                {
                    MessageBox.Show("Please enter valid IP addresses for the NAE's static IP address, subnet mask, and gateway.");
                    return;
                }

                nic.SetStaticIP(nae.StaticIPAddress.Address, nae.StaticIPAddress.SubnetMask, nae.StaticIPAddress.DefaultGateway);
                NIC.LoadNICs(this.comboAdapterList);
                nic.ReselectNIC(this.comboAdapterList);

                nic = (NIC)this.comboAdapterList.SelectedItem;
                FormHandler.UpdateNICText(nic, this.txtAdapterIPAddress, this.txtAdapterSubnetMask, this.txtAdapterDefaultGateway);
            }
            catch (Exception ex)
            {
                Logger.WriteMessage("Error in setting the static IP address.");
                Logger.WriteException(ex);
                Logger.PromptLogReview("There was an error in setting the static IP address.");
            }
        }
Esempio n. 6
0
        private void comboAdapterList_SelectedIndexChanged(object sender, EventArgs e)
        {
            NIC nic = (NIC)this.comboAdapterList.SelectedItem;

            FormHandler.UpdateNICText(nic, this.txtAdapterIPAddress, this.txtAdapterSubnetMask, this.txtAdapterDefaultGateway);
        }
Esempio n. 7
0
        public frmMain()
        {
            Logger.WriteMessage("Form initializing.");
            InitializeComponent();

            /** Setup grid view **/
            this.dataNAE.Columns.Add("name", "Property");
            this.dataNAE.Columns.Add("value", "Value");
            this.dataNAE.Columns[0].ReadOnly = true;
            this.dataNAE.Columns[1].Width    = (this.dataNAE.Width - this.dataNAE.Columns[0].Width) - 3;

            /** Used for assigning the correct menu to new site and NAE nodes in external classes **/
            frmMain.StaticContextSite = this.contextSite;
            frmMain.StaticContextNAE  = this.contextNAE;

            /** Load NICs into combo box **/
            NIC.LoadNICs(this.comboAdapterList);

            /** Check for existing configuration and load if applicable **/
            if (System.IO.File.Exists("default.xml"))
            {
                try
                {
                    FormHandler.XMLToTree(XDocument.Load("default.xml"), this.treeSites);
                    this.treeSites.ExpandAll();
                }
                catch (Exception e)
                {
                    Logger.WriteMessage("Error in loading default save file.");
                    Logger.WriteException(e);
                    Logger.PromptLogReview("An error occurred trying to load your previously saved configuration.");
                }
            }

            /** Start listening for packets **/
            try
            {
                IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
                if (allDevices.Count > 0)
                {
                    foreach (LivePacketDevice device in allDevices)
                    {
                        NAEListener listener = new NAEListener(device);
                        Task.Run((Action)listener.listen);
                    }
                }
                else
                {
                    MessageBox.Show("No network adapters were detected for listening and the NAE Listener will not function properly. Please ensure you have WinPCap installed.");
                }
            }
            catch (Exception e)
            {
                Logger.WriteMessage("Error in starting packet listeners");
                Logger.WriteException(e);
                Logger.PromptLogReview("An error occurred in starting the listener devices.");
                MessageBox.Show("Please note that since the listener devices failed to start, the NAE Listener tool will not function.");
            }

            /** Setup the NAE Handler **/
            NAEHandler.mainFrm = this;
            NAEHandler.Initialize();

            Logger.WriteMessage("Form initialized.");
        }
Esempio n. 8
0
 public static void UpdateNICText(NIC nic, TextBox txtIP, TextBox txtSubnet, TextBox txtGateway)
 {
     txtIP.Text      = nic.IP.Address;
     txtSubnet.Text  = nic.IP.SubnetMask;
     txtGateway.Text = nic.IP.DefaultGateway;
 }
Esempio n. 9
0
 public static void UpdateNICText(NIC nic, TextBox txtIP, TextBox txtSubnet, TextBox txtGateway)
 {
     txtIP.Text = nic.IP.Address;
     txtSubnet.Text = nic.IP.SubnetMask;
     txtGateway.Text = nic.IP.DefaultGateway;
 }