Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

A C# Ping Control

2.67/5 (15 votes)
9 Feb 2007CPOL 1   889  
This source code/control is provided to make it easy for programmers in C# to ping remote hosts and get the response time in milliseconds.

Sample image

Introduction

This control (with such an original name as DBnetPing 1.1!) has been designed to wrap the functionality of building an ICMP ping packet, sending it, and timing the response to give you an accurate ping time in milliseconds.

Usage

Simply drop the control onto your form and call the function:

C#
results = dBnetPing1.pingHost(txtHost.Text);

results is a simple class that lets you call GetResponseTimeMS which returns an int containing (yep - you guessed it) the response time in milliseconds:

C#
MessageBox.Show("Ping successfull! " + results.GetResponseTimeMS().ToString() + 
    " ms", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

Credits

I created this function/wrapper heavily based on already existing C# code; unfortunately, I do not remember the author. If anyone can help me here, I'd be glad to add. Kudos.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)