我正在开发一个c# .Net3.5应用程序。
应用程序使用WinVerifyTrust检查文件的签名。问题在于,在隔离网络上(即不能访问互联网,但机器仍然有IP地址),需要很长时间(~20秒)才能返回WinVerifyTrust。
有没有办法识别这种情况?
发布于 2012-10-24 07:12:46
你试过使用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 ) ;
}
}
发布于 2012-10-24 07:08:31
如果计算机连接到速度很慢的互联网连接,您将如何区分?
无论如何,你可以Ping google (比方说)看看它是否可用。如果计算机未隔离,它将可用。
要从C#执行ping操作,只需使用System.Net.NetworkInformation.Ping
google编辑:如果你需要支持代理,那么你应该通过端口80打开一个TcpConnection,然后检查你能不能。如果你不能打开一个连接到谷歌80的端口,你也不能连接到WinVerifyTrust。
https://stackoverflow.com/questions/13044352
复制