Thursday, April 1, 2010

Coding for checking status of ip with ping statment in asp.net with c#

string server_ip = "127.0.0.1";//address to verify, like 127.0.0.1
Ping _objPing = new Ping();
PingReply reply_ping;
reply_ping = p.Send(server_ip);
int ping_success = 0, ping_insuccess = 0;
for (int i = 0; i < 25; i++)
{
reply_ping = _objPing.Send(server_ip);
if (reply_ping.Address.ToString() == server_ip)
ping_success++;
else
ping_insuccess++;
Console.WriteLine("Pack. sent");
}
Console.WriteLine("sent = 4, recived = {0}, lost = {1}", ping_success, ping_insuccess);
Console.ReadKey();

No comments: