コード例 #1
0
        /// <summary>
        /// Loads current network configuration for the specified NIC and show in
        /// the current configuration block
        /// </summary>
        /// <param name="nicName"></param>
        private void loadCurrentSetting(string nicName)
        {
            string[] ipAddresses;
            string[] subnets;
            string[] gateways;
            string[] dnses;

            // Load current IP configuration for the selected NIC
            WMIHelper.GetIP(nicName, out ipAddresses, out subnets, out gateways, out dnses);

            // if network connection is disabled, no information will be available
            //if (null == ipAddresses || null == subnets || null == gateways || null == dnses)
            //    return;

            // Show the setting
            if (ipAddresses != null)
            {
                lblCurrentIP.Text = string.Join(",", ipAddresses);
            }
            if (subnets != null)
            {
                lblCurrentSubnet.Text = string.Join(",", subnets);
            }
            if (gateways != null)
            {
                lblCurrentGateway.Text = string.Join(",", gateways);
            }
            if (dnses != null)
            {
                lblCurrentDNS.Text = string.Join(",", dnses);
            }
        }
コード例 #2
0
        /// <summary>
        /// Applies configuration for the specified NIC
        /// </summary>
        /// <param name="nicName"></param>
        private void applyNIC(string nicName)
        {
            NICProfile nicProfile = getNICProfile(nicName);

            if (null == nicProfile)
            {
                return;
            }

            UpdateStatus("Setting configuration for: " + nicName);

            try
            {
                if (nicProfile.UseDHCP)
                {
                    WMIHelper.SetDHCP(nicName);
                }
                else
                {
                    WMIHelper.SetIP(nicProfile.Name, nicProfile.IP, nicProfile.Subnet, nicProfile.Gateway, nicProfile.DNS);
                }
            }
            catch (Exception x)
            {
                UpdateStatus("Error occured while setting network configuration.");
                UpdateStatus(x.Message);
                return;
            }

            UpdateStatus("Done.");
        }
コード例 #3
0
        /// <summary>
        /// Load NIC names
        /// </summary>
        private void loadNICs()
        {
            // get the NIC names
            ArrayList nicNames = WMIHelper.GetNICNames();

            // populate the NIC list
            cboNIC.Items.Clear();
            foreach (string name in nicNames)
            {
                cboNIC.Items.Add(name);
            }

            // if NIC found, select the first one
            if (cboNIC.Items.Count > 0)
            {
                cboNIC.SelectedIndex = 0;
                grpNIC.Enabled       = true;
            }
        }