I did a small program that ping my entire network, but I think I have a problem because some equipment stop working (it runs every 2 minutes and takes 1 minute to complete the operation), the question is:
?Is there a better way to do this?
Here the code:
Console.WriteLine("Haciendo ping a los equipos, no cierre esta ventana... ");
Ping ping = new Ping();
byte[] buffer = new byte[32];
PingOptions pingoptns = new PingOptions(128, true);
int timeout = Convert.ToInt32(ConfigurationManager.AppSettings["timeout"].ToString());
List<Equipo> list_Eq = new List<Equipo>();
DataTable dt = DB.ShowData("select ip from testping where estatus = 1");
// Por cada IP se realiza ping y se agrega a la lista del modelo
foreach (DataRow item in dt.Rows)
{
if (ping.Send(item[0].ToString(), timeout, buffer, pingoptns).Status == IPStatus.Success)
{
list_Eq.Add(new Equipo
{
ip = item[0].ToString(),
estado = 1
});
}
else
{
list_Eq.Add(new Equipo
{
ip = item[0].ToString(),
estado = 0
});
}
}
// Se actualiza el estado de las ip segun la respuesta del ping
foreach (var eq in list_Eq)
{
DB.ExecQuery("update testping set estado = " + eq.estado + " where ip = '" + eq.ip + "'");
}
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…