Esempio n. 1
0
        public static void findInterfaces()
        {
            inter.Clear();

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_NetworkAdapter WHERE Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\%'");
            ManagementObjectCollection objCol = searcher.Get();

            foreach (ManagementObject mgtObject in objCol)
            {

                Interface tmpInterface = new Interface();

                //PropertyData pd = mgtObject.Properties;
                foreach (PropertyData pd in mgtObject.Properties)
                {

                    String keyName = pd.Name;

                    if (keyName == "NetConnectionID")
                    {

                        String interfaceName = pd.Value.ToString();
                        tmpInterface.Name = interfaceName;

                    }
                    else if (keyName == "Description")
                    {
                        String interfaceDescription = pd.Value.ToString();
                        tmpInterface.Description = interfaceDescription;
                    }
                    else if (keyName == "AdapterType")
                    {
                        if (pd.Value != null)
                        {
                            String adapterType = pd.Value.ToString();
                            tmpInterface.Type = adapterType;
                        }

                    }
                    else if (keyName == "Index")
                    {
                        UInt32 interfaceIndex = (UInt32)pd.Value;
                        tmpInterface.ID = (int)interfaceIndex;
                    }
                    else if (keyName == "MACAddress")
                    {
                        if (pd.Value != null)
                        {
                            String macAddress = pd.Value.ToString();
                            tmpInterface.MacAddress = macAddress;
                        }
                    }
                    else if (keyName == "Manufacturer")
                    {
                        String manufacturer = pd.Value.ToString();
                        tmpInterface.Manufacturer = manufacturer;
                    }
                    else if (keyName == "NetConnectionStatus")
                    {
                        UInt16 connectionStatus = (UInt16)pd.Value;
                        tmpInterface.ConnectionStatus = (int)connectionStatus;
                    }
                    else if (keyName == "NetEnabled")
                    {
                        bool enabled = (bool)pd.Value;
                        tmpInterface.Enabled = enabled;
                    }

                }

                inter.Add(tmpInterface);
            }

            //load all the additional information
            for (int i = 0; i < inter.Count; i++)
            {

                searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index=" + inter[i].ID);

                objCol = searcher.Get();

                foreach (ManagementObject mgtObject in objCol)
                {

                    foreach (PropertyData pd in mgtObject.Properties)
                    {

                        String keyName = pd.Name;

                        if (keyName == "DHCPEnabled")
                        {
                            bool dhcpEnabled = (bool)pd.Value;
                            inter[i].DHCPEnabled = dhcpEnabled;
                        }
                        else if (keyName == "DHCPLeaseExpires")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].DHCPLeaseExpires = WMIDateTime(pd.Value.ToString());
                            }
                        }
                        else if (keyName == "DHCPLeaseObtained")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].DHCPLeaseStarted = WMIDateTime(pd.Value.ToString());
                            }
                        }
                        else if (keyName == "DHCPServer")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].DHCPServer = pd.Value.ToString();
                            }
                        }
                        else if (keyName == "DNSDomain")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].DNSSuffix = pd.Value.ToString();
                            }
                        }
                        else if (keyName == "DNSHostName")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].Hostname = pd.Value.ToString();
                            }
                        }
                        else if (keyName == "DefaultIPGateway")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].DefaultGateway = (String[])pd.Value;
                            }
                        }
                        else if (keyName == "IPAddress")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].IPAddresses = (String[])pd.Value;
                            }
                        }
                        else if (keyName == "DNSServerSearchOrder")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].DNSServers = (String[])pd.Value;
                            }
                        }
                        else if (keyName == "IPSubnet")
                        {
                            if (pd.Value != null)
                            {
                                inter[i].SubnetMasks = (String[])pd.Value;
                            }
                        }
                        else if (keyName == "IPEnabled") //XP Doesn't have NetEnabled attribute so use this instead
                        {
                            if (pd.Value != null)
                            {
                                bool enabled = (bool)pd.Value;
                                inter[i].Enabled = enabled;
                            }
                        }

                    }

                }

            }
        }
Esempio n. 2
0
 public static void addInterface(Interface newInterface)
 {
     inter.Add(newInterface);
 }
Esempio n. 3
0
        public static void renewDHCP(Interface currInt)
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index=" + currInt.ID);
            ManagementObjectCollection objCol = searcher.Get();

            foreach (ManagementObject mgtObject in objCol)
            {

                mgtObject.InvokeMethod("ReleaseDHCPLease", null);
                mgtObject.InvokeMethod("RenewDHCPLease", null);

            }
        }
Esempio n. 4
0
        private void loadInterface(String interfaceName)
        {
            showAction("Loading Interface");

            if (currInterface == null)
            {
                currInterface = Interfaces.findInterfacebyName(interfaceName);
            }else{
                lock (currInterface)
                {
                    currInterface = Interfaces.findInterfacebyName(interfaceName);
                }
            }

            hideAction();
        }