迷一样的逍遥人
晴带雨伞,包带干粮,点滴积累,水到渠成.

方式一:

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

posted on 2014-04-09 15:25  谜一样的逍遥人  阅读(139)  评论(0编辑  收藏  举报