zoukankan      html  css  js  c++  java
  • C​#​小​实​例​之​-​-​-​C​#​判​断​网​络

    方式一:

    [DllImport("wininet")]
    private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
    bool GetConnectedState()
    {
      try
      {
        int i = 0;
        if (InternetGetConnectedState(out i, 0))
          return true;
        else
          return false;
      }
      catch (System.Exception ex)  
      {
        return false;
      }
    }

    方式二:

    bool GetConnectedStateA()
    {
      try
      {
        Ping ping = new Ping();
        PingOptions poptions = new PingOptions();
        poptions.DontFragment = true;
        string data = string.Empty;
        byte[] buffer = Encoding.ASCII.GetBytes(data);

        int timeout = 1000;
        PingReply reply = ping.Send("192.168.1.100"), timeout, buffer, poptions);
        if (reply.Status == IPStatus.Success)
          return true;
        else
          return false;
        }
        catch (System.Exception ex)
        {
       
          return false;
        }
    }

  • 相关阅读:
    @@IDENTITY,SCOPE_IDENTITY和IDENT_CURRENT的辨析
    Blue Jeans[poj3080]题解
    绿色通道题解
    后缀数组
    Power Strings[poj2406]题解
    KMP算法
    Life Forms[poj3294]题解
    STM32固件库文件编程结构思想的理解
    GPIO设置
    HTML_v2
  • 原文地址:https://www.cnblogs.com/lzh_527/p/3654298.html
Copyright © 2011-2022 走看看