【问题标题】:How to identify an Isolated Network如何识别隔离网络
【发布时间】:2012-10-24 07:05:46
【问题描述】:

我正在开发一个 c# .Net3.5 应用程序。

应用程序使用WinVerifyTrust 检查文件的签名。问题是在孤立的网络上(即无法访问 Internet,但机器仍然有 IP 地址)需要很长时间(约 20 秒)才能返回 WinVerifyTrust。

有没有办法识别这种情况?

【问题讨论】:

    标签: c# .net-3.5 winverifytrust


    【解决方案1】:

    您是否尝试过使用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】:

      如果计算机连接到慢速互联网连接,您将如何区分?

      无论如何,您可以 Ping google(例如)查看它是否可用。如果计算机未隔离,它将可用。

      要从 C# ping 只需使用 System.Net.NetworkInformation.Ping

      编辑:如果您需要支持代理,那么您应该通过 google 端口 80 打开一个 TcpConnection 并检查您是否可以。如果您无法打开 google 的 80 端口,您也无法连接到 WinVerifyTrust。

      【讨论】:

      • 你说得对,但是在慢速网络连接上,我的应用程序运行缓慢是可以的,但在使用隔离网络时就不行了。
      • 无论我是否连接到互联网,尝试 ping google 时都会出现请求超时。
      • 你能发布你的代码吗?我过去曾多次这样做,并且有效。你能检查一下你是否也可以从命令行 ping google 吗?
      • @user844541:所以...?共同点:)
      • 什么??我想也许是防火墙阻止了 ping 响应。无论如何,我的观点是,即使您有互联网连接,ping 也会失败。因此,如果 ping 失败,不足以确定您是否连接到互联网。
      猜你喜欢
      • 2012-01-14
      • 1970-01-01
      • 2020-12-25
      • 1970-01-01
      • 2012-10-10
      • 1970-01-01
      • 2012-08-01
      相关资源
      最近更新 更多