I am not that much efficient in mvc. I want to continuously try pinging the IPs in the list and then render the data in Index view using Viewbag. but problem here is I have to refresh the page manually each and every time to get the current status of each and every IP.
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
List<string> IPlist = new List<string>();
IPlist.Add("10.0.1.151");
IPlist.Add("www.google.com");
IPlist.Add("192.168.0.1");
Ping myping = new Ping();
StringBuilder sc = new StringBuilder("Ping Status:");
foreach (string c in IPlist)
{
PingReply replytest = myping.Send(c, 1000);
if (replytest != null)
{
sc.Append(" Status : " + replytest.Status + " \n Time: " + replytest.RoundtripTime.ToString() + " \n Address : " + replytest.Address + " \n ");
}
else
{
sc.Append("Request Failed");
}
}
ViewBag.result = sc.ToString();
return View();
}
}