Posted By

rengber on 02/11/07


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ad5qa
emregulcan


Ping Using WMI Ping_Status


 / Published in: C#
 

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

  1. private string GetPingStatus(string serverName)
  2. {
  3. //Refer to: http://msdn2.microsoft.com/en-us/library/aa394350.aspx
  4.  
  5. PingStatus ps = new PingStatus(serverName.Trim(),32,false,0,false,"",0,1000,0,80,0);
  6. return GetPingStatusMessage(ps.PrimaryAddressResolutionStatus, ps.ProtocolAddress);
  7. }
  8.  
  9. private string GetPingStatusMessage(UInt32 status, string address)
  10. {
  11. string retVal = "Unknown Error";
  12. switch(status)
  13. {
  14. case 0:
  15. if(address.Length < 1)
  16. {
  17. retVal = "Timed Out";
  18. }
  19. else
  20. {
  21. retVal = "Resolved " + address;
  22. }
  23. break;
  24. case 11001:
  25. retVal = "Host Not Found";
  26. break;
  27. case 11002:
  28. retVal = "Destination Net Unreachable";
  29. break;
  30. case 11003:
  31. retVal = "Destination Host Unreachable";
  32. break;
  33. case 11004:
  34. retVal = "Destination Protocol Unreachable";
  35. break;
  36. case 11005:
  37. retVal = "Destination Port Unreachable";
  38. break;
  39. case 11006:
  40. retVal = "No Resources";
  41. break;
  42. case 11007:
  43. retVal = "Bad Option";
  44. break;
  45. case 11008:
  46. retVal = "Hardware Error";
  47. break;
  48. case 11009:
  49. retVal = "Packet Too Big";
  50. break;
  51. case 11010:
  52. retVal = "Request Timed Out";
  53. break;
  54. case 11011:
  55. retVal = "Bad Request";
  56. break;
  57. case 11012:
  58. retVal = "Bad Route";
  59. break;
  60. case 11013:
  61. retVal = "TimeToLive Expired Transit";
  62. break;
  63. case 11014:
  64. retVal = "TimeToLive Expired Reassembly";
  65. break;
  66. case 11015:
  67. retVal = "Parameter Problem";
  68. break;
  69. case 11016:
  70. retVal = "Source Quench";
  71. break;
  72. case 11017:
  73. retVal = "Option Too Big";
  74. break;
  75. case 11018:
  76. retVal = "Bad Destination";
  77. break;
  78. case 11032:
  79. retVal = "Negotiating IPSEC";
  80. break;
  81. case 11050:
  82. retVal = "General Failure";
  83. break;
  84. }
  85. return retVal;
  86. }

Report this snippet  

You need to login to post a comment.