c#检测网路连接

这里网上重复最多的,这里不是检测网络连接,而是网路。也就是你的物理设备连接了。你的网线连接到了交换机网关了。在计算机系统中的网络连接里面,你的本地连接显示已经连接上了。都是显示网路通了。用此方法。

[DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
        public extern static bool InternetGetConnectedState(out int conState, int reder);
        //参数说明 constate 连接说明 ,reder保留值
        private void button2_Click(object sender, EventArgs e)
        {
            int Desc = 0;
            if (InternetGetConnectedState(out  Desc, 0))
               label1.Text="已连接在网上!";
            else
                label1.Text="未连接在网上!!";
        }  

这里的连接了是指网路不是网络。

原文地址:https://www.cnblogs.com/jinyuttt/p/1805901.html