This tutorial will guide you through the process of pinging in Visual CSharp .Net.
Pinging an I.P. Address
Before creating the pinging function make sure you include a reference to System Net Network Information at the beginning of your class, like so:
using System.Net.NetworkInformation;
Now that you have the proper dependencies you can create a string function called PingHost with a String parameter called IPADRS. Create the String function using the source code found below:
public string PingHost(String IPADRS)
{
String Ret;
Ret = "";
using (Ping myPing = new Ping())
{
try
{
PingReply myReply = myPing.Send(IPADRS, 100);
if (myReply.Status == IPStatus.Success)
{
Ret = "Successfully Pinged IP Address: " + myReply.Address + " Time: " + myReply.RoundtripTime;
return Ret;
}
else
{
Ret = "Problem Pinging IP Address: " + myReply.Status.ToString();
return Ret;
}
}
catch (Exception ex)
{
Ret = "An Error was Encountered: " + ex.InnerException.Message;
return Ret;
}
}
return Ret;
}
This function will take the IP Address string parameter, ping it, and return the result of the pinging process making the PingHost String equal to the return value.
Conclusion
You have included the proper dependencies and create a pinging function, now all you have to do is call the function and supply the desired IP Address as a String parameter. Here is an example:
MessageBox.Show(PingHost("192.168.1.1"));
This code will attempt to ping the IP Address, 192.168.1.1, and a Message Box will show the results.
Published by James Cloud
I like to program and do basically anything that has to do with technology and computers. View profile
Photoshop Tutorial: Adding Digital Rain to Your ImagesLearn to enhance your photos by adding digital rain to them in Photoshop with this fun and easy step-by-step tutorial for intermediate Photoshop users.- Improve Your Ping Pong-Playing SkillsPing Pong is a game that requires quick hand eye coordination, and not necessarily the quick foot skills that many other sports or activities require. However like many other sports, the best way to make you a better...
- Real Estate Specializing: Triple Net Lease PropertyPrimary purpose for a Triple Net Lease (NNN) property, places responsibility to pay all property expenses upon the tenant or Lessor. This type of agreement is along term lease. Best suited for growth industries & econ...
A Tutorial to Troubleshoot Your Computer Network Using the PING UtilityThe PING command is a simple utility and many people have a very basic understanding of it. Here you'll learn more about how PING was created and how to use it for network trou...
- Photoshop Tutorial : How to Apply a Weather Effect to Your Text ?
- Photoshop Tutorial: Changing the Color Tone of Your Photos
- The Low Tech Idea Behind High Tech Mobile IP
- Tutorial: How to Sabotage Yourself
- Photoshop Tutorial: How to Digitally Create Beautiful White Teeth
- Beginner's Photoshop Tutorial: Learning to Create Your Own Brushes
- Photoshop Tutorial: Color Correcting and Tone Enhancing Photographs



