C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Network »

Ping remote computer in the network


Posted Date: 27 Mar 2007    Resource Type: Code Snippets    Category: Network
Author: Manikandan BalakrishnanMember Level: Gold    
Rating: 1 out of 5Points: 10



Normally we use dos command “ping” to know connection status of the remote machine, the same thing we can do using “System.Net.NetworkInformation.Ping” class. Using this class we can check the remote machine connected with the current machine or not. Also we can use “PingOptions” class to give the options to ping.

Here’s the sample code to ping a computer in your network.


public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string remoteMachineNameOrIP= "192.1.168.1";
int timeOut = 5;

Ping ping = new Ping();

// Pinging remote maching
PingReply reply = ping.Send(remoteMachineNameOrIP, timeOut);

// Displaying the result
StringBuilder sb = new StringBuilder();
sb.Append("Address:" + reply.Address.ToString());
sb.Append("\nStatus:" + reply.Status.ToString());
sb.Append("\nRoundtripTime:" + reply.RoundtripTime.ToString());

MessageBox.Show(sb.ToString(), "Ping Result: " + remoteMachineNameOrIP);
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Building a Simple File download server using C#
Previous Resource: Retrieving TCP connections information
Return to Discussion Resource Index
Post New Resource
Category: Network


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use