在WEB应用程序,利用ASP.net语言编写代码,来判断当前运行此代码的机器是否连接到互联网上,具体操作如下:
 
    第一步:在自定义的类声明下先定义声明外部API函数(即先导入外部API函数)如下声明定义:
   //检测网络连接是否连接到Internet
   [DllImport("wininet.dll")]
   private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
 
   第二步:在自定义类中创建自定义的方法来调用导入的外部API函数来判断机器是否连接到Internet上,如下创建并调用:
   public bool IsConnected()
   {
      int connectionDescription = 0;
        //判断是否连接到外网上的函数,并返回布尔值
      return InternetGetConnectedState(out connectionDescription, 0);
   }

相关文章:

  • 2021-08-29
  • 2021-11-01
  • 2022-02-13
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-10-09
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2021-11-30
相关资源
相似解决方案