Пример #1
0
        public static Ethernet[] GetNetworkDevices()
        {
            NetworkInterface[] ifaces    = NetworkInterface.GetAllNetworkInterfaces();
            Ethernet[]         ethernets = new Ethernet[ifaces.Length];
            try
            {
                int count = 0;
                foreach (NetworkInterface iface in ifaces)
                {
                    String ip   = "0.0.0.0";
                    String mask = "255.255.255.255";
                    IPInterfaceProperties properties = iface.GetIPProperties();
                    foreach (UnicastIPAddressInformation unicast in properties.UnicastAddresses)
                    {
                        if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            ip   = unicast.Address.ToString();
                            mask = unicast.IPv4Mask.ToString();
                            break;
                        }
                    }

                    ethernets[count] = new Ethernet(iface.Name, ip, mask, iface.GetIPv4Statistics().BytesReceived, iface.GetIPv4Statistics().BytesSent);
                    count++;
                }
            }
            catch (Exception e)
            {
                LogMan.AddLog("Error fetching Network Devices: " + e.Message);
            }
            return(ethernets);
        }
Пример #2
0
        public static Ethernet[] GetNetworkDevices()
        {
            NetworkInterface[] ifaces = NetworkInterface.GetAllNetworkInterfaces();
            Ethernet[] ethernets = new Ethernet[ifaces.Length];
            try
            {
                int count = 0;
                foreach (NetworkInterface iface in ifaces)
                {
                    String ip = "0.0.0.0";
                    String mask = "255.255.255.255";
                    IPInterfaceProperties properties = iface.GetIPProperties();
                    foreach (UnicastIPAddressInformation unicast in properties.UnicastAddresses)
                        if (unicast.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            ip = unicast.Address.ToString();
                            mask = unicast.IPv4Mask.ToString();
                            break;
                        }

                    ethernets[count] = new Ethernet(iface.Name, ip, mask, iface.GetIPv4Statistics().BytesReceived, iface.GetIPv4Statistics().BytesSent);
                    count++;
                }
            }
            catch (Exception e)
            {
                LogMan.AddLog("Error fetching Network Devices: " + e.Message);
            }
            return ethernets;
        }