In my last post, I shared some code in VBScript to PING a remote server to check for availability before attempting to use a resource on that remote server. This wouldn’t be my blog if I didn’t also share this code in C# as well. IMO, this sort of thing is a far better suited for a .NET Extension if for the SalesLogix Windows client.
To perform a PING using C#, the code is far more straight forward than the VBScript version. No need for shelling the command out and reading back the StdOut. This version reads much nicer:
using System; using System.Management; namespace FX.Network.Utility { public class NetworkDiscovery { public NetworkDiscovery() { } public static bool Ping(string Target) { SelectQuery query = new SelectQuery("Win32_PingStatus", string.Format("Address='{0}'", Target)); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); foreach (ManagementObject result in searcher.Get()) { return (result["StatusCode"] != null && (0 == (UInt32)result["StatusCode"])); } return false; } } }
Enjoy!




Hi ryan!I wonder if you can help me doing a code for C# on how to ping sever and will display its TTL and latency same thing when you ping a server using CMD prompt, also to display whether the handshake was successful or not.I will really appreciate if you can do it for me.thanks in advanced.