/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private string GetPingStatus(string serverName) { //Refer to: http://msdn2.microsoft.com/en-us/library/aa394350.aspx 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; }
URL: http://danielvl.blogspot.com/2004/06/how-to-ping-in-c-using.html