How to identify an Isolated Network

2019-08-01 13:06发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-01 13:37

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 ) ;
        }
    }
查看更多
Anthone
3楼-- · 2019-08-01 13:58

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.

查看更多
登录 后发表回答