Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

Ping a Remote Server Using C#

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;


What's This?
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series

Related Content
   Better Code Organization for Infor CRM (Saleslogix) Mobile Customizations
When customizing the Infor CRM (Saleslogix) Mobile client, it's common for the ApplicationModule to g
Posted on May 05, 2015 by Ryan Farley to Ryan Farley's Blog
   Index of Posts for Starting with Infor CRM (Saleslogix) Development
The blogs on customerfx.com go all the way back to 2003. There's years and years worth of information
Posted on Dec 30, 2014 by Ryan Farley to Ryan Farley's Blog
   Easily Showing and Hiding Tabs at Runtime in Infor CRM (Saleslogix)
Showing and hiding tabs in the Infor CRM (Saleslogix) client should be an easy thing. It should be someth
Posted on Dec 16, 2014 by Ryan Farley to Ryan Farley's Blog
   Avoiding the Dirty Data Message When Programatically Redirecting to a Record in Infor CRM (Saleslogix)
In my last post I wrote about using the OnClientClick property of a control (or button) to run JavaScript
Posted on Dec 02, 2014 by Ryan Farley to Ryan Farley's Blog
   Confirming Actions With an "Are you sure?" Prompt in Infor CRM (Saleslogix)
I'm not a huge fan of bugging end users. I figure, if an end user clicked something, he or she meant
Posted on Nov 18, 2014 by Ryan Farley to Ryan Farley's Blog


barns le tourneur said:

are you aware of the .NET Class:



Ping pinger = Ping();

PingReply reply = pinger.Send(boxToPing);

coz this may make your life a little easier.


May 26, 2008 4:39 AM

Ryan Farley said:

Hello barns le tourneur!

Thanks for the comment. The NetworkInformation namespace came in the .NET 2.0 Framework. My code dates before that from one of my own libraries. I'll often forget about new things that come into the framework after already being used to my own code. Hehe. Thanks!


May 26, 2008 6:44 PM

Chris Grant said:

Or in VB.NET

My.Computer.Network.Ping(<ip or hostname>)

November 9, 2008 3:40 AM

khemlall.info, Performance Testing Tip, Tricks, Scripting and more said:

Pingback from  khemlall.info, Performance Testing Tip, Tricks, Scripting and more

March 20, 2011 9:00 PM

khemlall.info, Performance Testing Tip, Tricks, Scripting and more said:

Pingback from  khemlall.info, Performance Testing Tip, Tricks, Scripting and more

March 20, 2011 9:00 PM

trisha said:

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.

August 7, 2012 9:55 PM

Leave a Comment

All contents Copyright © 2015 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register