Return to Snippet

Revision: 2412
at February 11, 2007 16:49 by rengber


Initial Code
private string GetPingStatus(string serverName)
{
//Refer to: http://msdn2.microsoft.com/en-us/library/aa394350.aspx

  PingStatus ps = new PingStatus(serverName.Trim(),32,false,0,false,"",0,1000,0,80,0); 
  return GetPingStatusMessage(ps.PrimaryAddressResolutionStatus, ps.ProtocolAddress); 
}

private string GetPingStatusMessage(UInt32 status, string address)
{
  string retVal = "Unknown Error"; 
  switch(status)
  {
    case 0: 
      if(address.Length < 1)
      {
        retVal = "Timed Out"; 
      }
      else
      {
        retVal = "Resolved " + address; 
      }
      break; 
    case 11001:
      retVal = "Host Not Found";
      break;
    case 11002:
      retVal = "Destination Net Unreachable"; 
      break; 
    case 11003: 
      retVal = "Destination Host Unreachable"; 
      break;
    case 11004:
      retVal = "Destination Protocol Unreachable"; 
      break; 
    case 11005: 
      retVal = "Destination Port Unreachable"; 
      break;
    case 11006:
      retVal = "No Resources"; 
      break;
    case 11007: 
      retVal = "Bad Option"; 
      break;
    case 11008: 
      retVal = "Hardware Error"; 
      break;
    case 11009: 
      retVal = "Packet Too Big"; 
      break;
    case 11010: 
      retVal = "Request Timed Out"; 
      break;
    case 11011: 
      retVal = "Bad Request"; 
      break;
    case 11012: 
      retVal = "Bad Route"; 
      break;
    case 11013: 
      retVal = "TimeToLive Expired Transit"; 
      break;
    case 11014: 
      retVal = "TimeToLive Expired Reassembly"; 
      break;
    case 11015: 
      retVal = "Parameter Problem"; 
      break;
    case 11016: 
      retVal = "Source Quench"; 
      break;
    case 11017: 
      retVal = "Option Too Big"; 
      break;
    case 11018: 
      retVal = "Bad Destination"; 
      break;
    case 11032: 
      retVal = "Negotiating IPSEC"; 
      break;
    case 11050: 
      retVal = "General Failure"; 
      break; 
  }
  return retVal; 
}

Initial URL
http://danielvl.blogspot.com/2004/06/how-to-ping-in-c-using.html

Initial Description

                                

Initial Title
Ping Using WMI Ping_Status

Initial Tags

                                

Initial Language
C#