Check network status

I want to check the status of the network, if the network is down, I mean if my network is down, I want to figure out programmatically using C # / VB.net to figure out which router or server, etc. which is also disabled,

Hopefully I'll explain my question if you want more explanation. Tell me please.

I want to check if there is a router in the network connection or some other problem. Since there are many methods of checking up or down the network, but because of which the device on the network works net, that is my problem.

+2


source to share


3 answers


Why not use .Net networking classes?



http://msdn.microsoft.com/en-us/library/system.net.networkinformation.aspx

+1


source


You can pinvoke InternetGetConnectedState () . Pass 0 for flags and if it returns true there is an active internet connection.



+1


source


For some of my 3-tier WCF applications, I use a multi-stage test to check why I cannot access the online data.

First we check if the computer is in quarantine (saw this feature when starting Windows 2008)

ManagementScope scope = new ManagementScope(@"\root\nap");
scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM NAP_Client");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
    int isolationState = 0;
    foreach (ManagementObject m in searcher.Get())
    {
        isolationState = int.Parse(m["systemIsolationState"].ToString());
    }

    if (isolationState == 3) // 3 means in quarantine
    {
        //NAP is preventing the computer access to the network
        ....do something
    }
}

      

We will then continue testing if we have access to the internet using this API:

[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out ConnectedStateFlag lpdwFlags, int dwReserved);

[Flags]
private enum ConnectedStateFlag : int
{
    Configured = 0x40,
    LAN = 0x02,
    RasInstalled = 0x10,
    Modem = 0x01,
    ModemBusy = 0x08,
    Offline = 0x20,
    Proxy = 0x04
}

      

Then I open a socket and try to connect to the server address.

Then I'll try to instantiate the web service to check if IIS is working correctly and not throwing any errors.

Then I call a function in the web service that tells me if the database is online.

0


source







All Articles