检测网络状态

        /// <summary>
        /// Retrieves the connected state of the local system
        /// </summary>
        /// <param name="lpdwFlags">Pointer to a variable that receives the connection description. This parameter may return a valid flag even when the function returns FALSE. This parameter can be one or more of the following values.</param>
        /// <param name="dwReserved">This parameter is reserved and must be 0.</param>
        /// <returns>Returns TRUE if there is an active modem or a LAN Internet connection, or FALSE if there is no Internet connection, or if all possible Internet connections are not currently active. For more information, see the Remarks section. 
        /// When InternetGetConnectedState returns FALSE, the application can call GetLastError to retrieve the error code</returns>
        [DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
        public extern static bool InternetGetConnectedState(out StateFlags lpdwFlags, int dwReserved);


    public enum StateFlags : int
    {
        /// <summary>
        /// Local system uses a modem to connect to the Internet.
        /// </summary>
        INTERNET_CONNECTION_MODEM = 0x01,
        /// <summary>
        /// Local system uses a local area network to connect to the Internet.
        /// </summary>
        INTERNET_CONNECTION_LAN = 0x02,
        /// <summary>
        /// Local system uses a proxy server to connect to the Internet.
        /// </summary>
        INTERNET_CONNECTION_PROXY = 0x04,
        /// <summary>
        /// No longer used.
        /// </summary>
        INTERNET_CONNECTION_MODEM_BUSY = 0x08,
        /// <summary>
        /// Local system has RAS installed.
        /// </summary>
        INTERNET_RAS_INSTALLED = 0x10,
        /// <summary>
        /// Local system is in offline mode.
        /// </summary>
        INTERNET_CONNECTION_OFFLINE = 0x20,
        /// <summary>
        /// Local system has a valid connection to the Internet, but it might or might not be currently connected.
        /// </summary>
        INTERNET_CONNECTION_CONFIGURED = 0x40
    }

 

转载于:https://www.cnblogs.com/wjshan0808/p/4221607.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值