How to identify an Isolated Network

491 views Asked by At

I am developing a c# .Net3.5 application.

The applications checks the signature of files using WinVerifyTrust. The problem is that on isolated networks (i.e. no Internet access but machine still has an IP address) it takes a very long time (~20 seconds) until WinVerifyTrust returns.

Is there a way to identify this situation?

2

There are 2 answers

6
Ignacio Soler Garcia On

And how you will differentiate if the computer is connected with a slow internet connection?

Anyway you can Ping google (for example) to see if it's available. If the computer is not isolated it will be available.

To ping from C# just use System.Net.NetworkInformation.Ping

EDIT: if you need to support being behind a proxy then you should open a TcpConnection over the google port 80 and check if you can or you cannot. If you cannot open a port to google's 80 you cannot connect to WinVerifyTrust either.

0
Rohit Vats On

Have you tried using the Windows API-

using System;
using System.Runtime;
using System.Runtime.InteropServices;

    public class InternetCS
    {
        //Creating the extern function...
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState( out int Description, int ReservedValue );

        //Creating a function that uses the API function...
        public static bool IsConnectedToInternet( )
        {
            int Desc ;
            return InternetGetConnectedState( out Desc, 0 ) ;
        }
    }