Iam a very newbie new person here :)
I want to ping a server, (checking availability) from the console application. If it answers then the program continues, if not, displays error message. Can anybody tell me how to do this?
SO again:
1.)
The program asks for server address.
(e.g.: eu.logon.com)
2.)
Then its pings
it.
3.)
And if the server answers the the
program continues, if its doesnt, then error message.
Source code would be the best, thanks!

Rajeswari nathan97 reputationPosted Sep 29, 2009, 9:22 PM EDT
using System;
using System.Net.NetworkInformation;
class MainClass {
public static void Main(string[] args) {
using (Ping ping = new Ping()) {
Console.WriteLine("Pinging:");
foreach (string comp in args) {
try {
Console.Write(" {0}...", comp);
PingReply reply = ping.Send(comp, 100);
if (reply.Status == IPStatus.Success) {
Console.WriteLine("Success - IP Address:{0}", reply.Address, reply.RoundtripTime);
} else {
Console.WriteLine(reply.Status);
}
} catch (Exception ex) {
Console.WriteLine("Error ({0})",
ex.InnerException.Message);
}
}
}
}
}
Christopher Leeiy4 reputationPosted Sep 30, 2009, 4:30 AM EDT
Here is my code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Ping2 { class Program { static void Main(string[] args) { string adress; Console.WriteLine("Enter server adress:"); adress = Console.ReadLine(); // PING Adress Here // If answers then the program continue... // If not, error message, and exit. } } }Porgram pings, and if its answers then the program continues, if not its exits.
This is all I would like to do. I dont have to display any results, its just a check.