var listIP = new List<String>(); foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) { if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { var ipStr = ip.Address.ToString(); if (!(ipStr.StartsWith("169") || ipStr.EndsWith(".1") || ipStr.EndsWith(".255"))) listIP.Add(ipStr); } } } } return String.Join(Environment.NewLine, listIP);
获取动态信息
1 2 3 4 5 6 7 8 9
//获取CPU使用率 this.CpuPC = new PerformanceCounter("Processor", "% Processor Time", "_Total"); this.CpuPC.NextValue() //获取可用内存 this.RamPC = new PerformanceCounter("Memory", "Available KBytes"); this.RamPC.NextValue() //获取磁盘性能 this.DiskPC = new PerformanceCounter("PhysicalDisk", "% Idle Time", "_Total"); this.DiskPC.NextValue()