码迷,mamicode.com
首页 > Windows程序 > 详细

C#检测本地网络状态

时间:2016-06-21 22:33:19      阅读:387      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Runtime.InteropServices;

public static class NetTool
{
    [Flags]
    private enum ConnectionState
    {
        INTERNET_CONNECTION_MODEM = 0x1,
        INTERNET_CONNECTION_LAN = 0x2,
        INTERNET_CONNECTION_PROXY = 0x4,
        INTERNET_RAS_INSTALLED = 0x10,
        INTERNET_CONNECTION_OFFLINE = 0x20,
        INTERNET_CONNECTION_CONFIGURED = 0x40
     }

    [DllImport("wininet.dll", CharSet = CharSet.Auto)]
    static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);

    public static bool IsConnectedToInternet()
    {
        ConnectionState description = 0;
        bool conn = InternetGetConnectedState(ref description, 0);
        return conn;
    }
}        

C#检测本地网络状态

标签:

原文地址:http://www.cnblogs.com/taixihuase/p/5605113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!