gpt4 book ai didi

c# - 如何确定网络接口(interface)是否连接到互联网(即计算机在线)

转载 作者:太空狗 更新时间:2023-10-30 00:57:59 24 4
gpt4 key购买 nike

我需要一种以编程方式确定互联网可用性的方法。现在我使用 Ping 不断地 ping 一些互联网网站。

但 Windows 7 似乎以其他方式决定了互联网可用性。如果计算机在线,系统托盘中的网络接口(interface)图标上会出现地球图标。

问题是:是否有任何标准的 Win32 方法来检查在线状态、获胜事件或其他东西,如果有,如何在 C# 中使用它?

最佳答案

我相信这样的事情会起作用,尽管你的问题似乎是重复的:

using System;
using System.Runtime;
using System.Runtime.InteropServices;

public class InternetCS
{
//Creating the extern function...
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int Description, int ReservedValue );

//Creating a function that uses the API function...
public static bool IsConnectedToInternet( )
{
int Desc ;
return InternetGetConnectedState( out Desc, 0 ) ;
}
}

在这里寻找:

check whether Internet connection is available with C#

关于c# - 如何确定网络接口(interface)是否连接到互联网(即计算机在线),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3922394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com