How to identify an Isolated Network

僤鯓⒐⒋嵵緔 提交于 2019-12-11 11:19:29

问题


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?


回答1:


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 ) ;
        }
    }



回答2:


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.



来源:https://stackoverflow.com/questions/13044352/how-to-identify-an-isolated-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!