C#檢測本機是否聯網

蘭博丶專屬發表於2018-06-16

public class Net
{
[DllImport(“wininet”)]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);

/// <summary>
/// 檢測本機是否聯網
/// </summary>
/// <returns></returns>
public static bool IsConnectedInternet()
{
int i = 0;
if (InternetGetConnectedState(out i, 0))
{
//已聯網
return true;
}
else
{
//未聯網
return false;
}

}

}

相關文章