示例#1
0
文件: frmMain.cs 项目: kite29/IPBuddy
        private void btnLaunch_Click(object sender, EventArgs e)
        {
            if (this.treeSites.SelectedNode == null)
            {
                MessageBox.Show("Please select an NAE to launch.");
                return;
            }

            if (this.treeSites.SelectedNode.Tag is NAE)
            {
                try
                {
                    NAE nae = (NAE)this.treeSites.SelectedNode.Tag;

                    if (!StaticIP.IsIPv4(nae.IPAddress))
                    {
                        MessageBox.Show("Please enter a valid IP address for the NAE.");
                        return;
                    }

                    nae.Launch();
                }
                catch (Exception ex)
                {
                    Logger.WriteMessage("Error in launching NAE.");
                    Logger.WriteException(ex);
                    Logger.PromptLogReview("There was an error launching the NAE.");
                }
            }
            else
            {
                MessageBox.Show("Please select an NAE to launch.");
                return;
            }
        }
示例#2
0
 public static StaticIP FromXML(XElement xip)
 {
     StaticIP ip = new StaticIP { Address = xip.Element("Address").Value,
                                  SubnetMask = xip.Element("SubnetMask").Value,
                                  DefaultGateway = xip.Element("DefaultGateway").Value };
     return ip;
 }
示例#3
0
        public static StaticIP FromXML(XElement xip)
        {
            StaticIP ip = new StaticIP {
                Address        = xip.Element("Address").Value,
                SubnetMask     = xip.Element("SubnetMask").Value,
                DefaultGateway = xip.Element("DefaultGateway").Value
            };

            return(ip);
        }
示例#4
0
        public static NAE FromXML(XElement xnae)
        {
            NAE nae = new NAE {
                Name            = xnae.Attribute("Name").Value,
                IPAddress       = xnae.Element("IPAddress").Value,
                MAC             = xnae.Element("MAC").Value,
                OSVersion       = xnae.Element("OSVersion").Value,
                MSEAVersion     = xnae.Element("MSEAVersion").Value,
                NeuronID        = xnae.Element("NeuronID").Value,
                StaticIPAddress = StaticIP.FromXML(xnae.Element("StaticIP"))
            };

            return(nae);
        }
示例#5
0
文件: NIC.cs 项目: jmgilman/IPBuddy
        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;
            }
        }
示例#6
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;
            }
        }
示例#7
0
文件: frmMain.cs 项目: kite29/IPBuddy
        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.");
            }
        }