Пример #1
0
 public static void ConsoleWriteStatus(NetworkInfo info)
 {
     Console.WriteLine("=========================================");
     Console.WriteLine("Device Name:" + info.DeviceName);
     Console.WriteLine("Adapter Type:" + info.AdapterType);
     Console.WriteLine("MAC ID:" + info.MacAddress);
     Console.WriteLine("Connection Name:" + info.ConnectionID);
     Console.WriteLine("IP Address:" + info.IP);
     Console.WriteLine("Connection Status:" + info.Status.ToString());
     Console.WriteLine("=========================================");
 }
Пример #2
0
        static NetworkManager()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID IS NOT NULL");

            foreach (ManagementObject mo in searcher.Get())
            {
                NetworkInfo info = new NetworkInfo();
                info.DeviceName   = ParseProperty(mo["Description"]);
                info.AdapterType  = ParseProperty(mo["AdapterType"]);
                info.MacAddress   = ParseProperty(mo["MACAddress"]);
                info.ConnectionID = ParseProperty(mo["NetConnectionID"]);
                info.Status       = (NetConnectionStatus)Convert.ToInt32(mo["NetConnectionStatus"]);
                SetIP(info);
                m_Informations.Add(info.ConnectionID, info);
            }
        }
Пример #3
0
        void Update()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID IS NOT NULL");

            foreach (ManagementObject mo in searcher.Get())
            {
                try
                {
                    if (m_Informations.ContainsKey(ParseProperty(mo["NetConnectionID"])))
                    {
                        NetConnectionStatus status = (NetConnectionStatus)Convert.ToInt32(mo["NetConnectionStatus"]);
                        NetworkInfo         info   = m_Informations[ParseProperty(mo["NetConnectionID"])];
                        info.DeviceName   = ParseProperty(mo["Description"]);
                        info.AdapterType  = ParseProperty(mo["AdapterType"]);
                        info.MacAddress   = ParseProperty(mo["MACAddress"]);
                        info.ConnectionID = ParseProperty(mo["NetConnectionID"]);
                        info.Status       = status;
                        if (info.Status != NetConnectionStatus.Connected)
                        {
                            info.IP             = "0.0.0.0";
                            info.Mask           = "0.0.0.0";
                            info.DefaultGateway = "0.0.0.0";
                        }
                        else
                        {
                            SetIP(info);
                        }
                        //m_Informations[ParseProperty(mo["NetConnectionID"])] = info;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("[Update]:" + ex.Message);
                }
            }
        }