如何检测网络接口是否启用/禁用?
public Boolean IsNicEnabled(String nic) { return true; }
You could take a look at System.Net.NetworkInformation.NetworkInterface class about this.
Querying interface status can be done using the NetworkInterface.GetIsNetworkAvailable()
method call.
Example:
var adapters = NetworkInterface.GetAllNetworkInterfaces();
if (adapters != null && adapters.Length > 0)
{
foreach (NetworkInterface adapter in adapters)
{
Console.WriteLine("Network interface {0} is {1}",
adapter.Name,
(NetworkInterface.GetIsNetworkAvailable()?"up":"down")
);
}
}
The above code will yield results as:
Network interface Local Area Network is up
Network interface Loopback Pseudo-Interface 1 is up
Now you can encapsulate this into your property's getter for instance you just need to add filtering for the adapters name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.