C# 判断是否联网

public static class Internet
    {
        [DllImport("winInet.dll")]
        private static extern bool InternetGetConnectedState(ref int dwFlag, int dwReserved);
      
        /// <summary>
        /// 返回网络状态
        /// </summary>
        public static bool Status
        {
            get
            {
                Int32 dwFlag = new int();
                if (!InternetGetConnectedState(ref dwFlag, 0))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }
    }

  

posted on 2020-11-18 16:45  itprobie-菜鸟程序员  阅读(231)  评论(0编辑  收藏  举报