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

  • 相关阅读:
    vim配置文件
    NGUI屏幕自适应解决方案
    配置java环境
    Ignore files which are already versioned
    Unity3D TestTool Part _1
    c# 语法
    Application.persistentDataPath 的一个小坑
    Unity3D Log 收集机制
    Android 问题流水总结
    Open Phone, SMS, Email, Skype and Browser apps of Android in Unity3d
  • 原文地址:https://www.cnblogs.com/lzh_527/p/3654298.html
Copyright © 2020-2023  润新知