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;
        }
    }
}

Enjoy!

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
   Using a Test Plan
So you have approved the Statement of Work (SOW) for some modifications and are awaiting the delivery of
Posted on Mar 13, 2014 by George Jensen to George Jensen's Blog
 
   Creating a Saleslogix Ticket Pretty Prefix and Suffix in External Applications
Some entities in SalesLogix, such as Tickets, use a "pretty key" as an easier to use value to r
Posted on Feb 28, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Evaluating strings in C# Code snippets
When checking for two (or more) different values for a property in a code snippet, you can't simply l
Posted on Dec 13, 2013 by Jason Buss to Jason Buss' Blog
 
   Introducing the SalesLogix Mobile Developer Toolkit
I am very pleased to announce a new & free open source tool from Customer FX named the SalesLogix Mob
Posted on Nov 13, 2012 by Ryan Farley to Ryan Farley's Blog
 
   Exporting Table data via the SalesLogix web client
Recently, I had a request to create export functionality for a datagrid in the SalesLogix web client. I
Posted on Feb 22, 2012 by Jason Buss to Jason Buss' Blog
 
Comments

 

barns le tourneur said:

are you aware of the .NET Class:

System.Net.NetworkInformation.Ping

try:

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!

-Ryan

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

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 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