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 nathanPosted Sep 30, 2009, 1:22 AM
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 LeeiyPosted Sep 30, 2009, 8:30 AM
Here is my code:
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.