局域网连接已启动或断开

Lan connection is up or down

本文关键字:断开 启动 连接 局域网      更新时间:2023-10-16

c++ 或 c# 的 wince 7 中,找出 LAN 连接是打开还是关闭的方法是什么?

您可以从 c# 或 c++ 应用程序中使用 ipConfig 命令行工具,它提供所有网络适配器的状态。

此问题可能很有用:在 C# 中检查网络状态

bool networkUp
    = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

试试这个:

try
{
System.Net.IPHostEntry entry = System.Net.Dns.GetHostByName("hostname");
// found host
}
catch(System.Net.Socket.SocketException)
{
//host not found == LAN not connected!
}
可以在

.NET 中使用NetworkChange类。对于 LAN 连接,请使用NetworkInterface.GetIsNetworkAvailable()方法。

Return Value
Type: System.Boolean
true if a network connection is available; otherwise, false.

也看看那些;

System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged
System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged