public void UpdateStatistics(SessionPanel sessionPanel, PingSession pingSession) { sessionPanel.HostLabel.Text = pingSession.Host; sessionPanel.TitleLabel.Text = pingSession.Title; sessionPanel.PacketLossLabel.Text = pingSession.PacketLostPercent.ToString() + "%"; if (pingSession.PacketLostPercent < 100) { ICMPReply lastReply = pingSession.ReplyQueue.Last(); if (lastReply.Status == System.Net.NetworkInformation.IPStatus.Success) { sessionPanel.LastDelayLabel.Text = lastReply.RoundtripTime.ToString() + "ms"; } else { sessionPanel.LastDelayLabel.Text = lastReply.Status.ToString(); } sessionPanel.AvgLabel.Text = pingSession.AverageLatency.ToString() + " ms"; sessionPanel.MaxLabel.Text = pingSession.MaxLatency.ToString() + " ms"; sessionPanel.MinLabel.Text = pingSession.MinLatency.ToString() + " ms"; sessionPanel.JitterLabel.Text = pingSession.Jitter.ToString() + " ms"; } else { sessionPanel.LastDelayLabel.Text = pingSession.ReplyQueue.Last().Status.ToString(); sessionPanel.AvgLabel.Text = "N/A"; sessionPanel.MaxLabel.Text = "N/A"; sessionPanel.MinLabel.Text = "N/A"; sessionPanel.JitterLabel.Text = "N/A"; } }
public void Add(ICMPReply newReply) { log.Debug("Adding new reply"); ReplyQueue.Enqueue(newReply); if (ReplyQueue.Count > MaxLength) { log.Debug("Reply queue to large. Dequeueing oldest item"); ReplyQueue.Dequeue(); } log.Debug("Queue size [" + ReplyQueue.Count + "]"); ComputeStatistics(); log.Debug("Completed Add"); }
private ICMPReply SendPing() { Ping pinger = new Ping(); PingReply reply = null; ICMPReply replyWrapper = null; try { reply = pinger.Send(Host); replyWrapper = new ICMPReply(reply); }catch (PingException e) { replyWrapper = new ICMPReply(); //todo: this throws an exception if it's a hostname instead of an IP address replyWrapper.Address = System.Net.IPAddress.Parse(Host); replyWrapper.Status = IPStatus.IcmpError; } return(replyWrapper); }
private void Run() { while (isRunning) { ICMPReply reply = SendPing(); pingSession.Add(reply); PingReplyReceivedEventArgs args = new PingReplyReceivedEventArgs(); args.PingSession = pingSession; if (PingReplyRecieved != null) { PingReplyRecieved(this, args); } Thread.Sleep(delay); } log.Info("PingMonitor to host [" + Host + "] terminated"); }