public void DisplayStatistics(PingItem pingItem) { // Update the ping statistics label with the current // number of pings sent, received, and lost. pingItem.PingStatisticsText = $"Sent: {pingItem.Statistics.PingsSent} Received: {pingItem.Statistics.PingsReceived} Lost: {pingItem.Statistics.PingsLost}"; }
private void Overlay_Loaded(object sender, RoutedEventArgs e) { // Start topmost updater _winHook = new WindowHook(); _winHook.BrawlhallaOpened += (_, __) => MessageBox.Show("bh opened"); _winHook.WindowFocused += (_, __) => this.Topmost = true; _winHook.LostWindowFocus += (_, __) => this.Topmost = false; // Add ping items var config = ConfigManager.GetPingConfig(); foreach (var server in config.ServersEnabled) { var item = new PingItem(server.Name, Utilities.GetIPToPingFromName(server.Name), server.XPos, server.YPos); (this.Content as Canvas).Children.Add(item); item.MoveTo(item.XPos, item.YPos); } // Create low level mouse hook LowLevelMouseHook.Hook(); // Handle moving of ping items LowLevelMouseHook.MouseDown += Overlay_MouseDown; LowLevelMouseHook.MouseMoved += Overlay_MouseMoved; LowLevelMouseHook.MouseUp += Overlay_MouseUp; }
public void DisplayTcpReply(PingItem pingItem, bool isPortOpen, int portnumber, int errorCode) { if (pingItem.PingBackgroundWorker.CancellationPending) { return; } // Prefix the ping reply output with a timestamp. var pingOutput = new StringBuilder($"[{DateTime.Now.ToLongTimeString()}] Port {portnumber.ToString()}: "); if (isPortOpen) { pingOutput.Append("OPEN"); } else { pingOutput.Append("CLOSED"); } // Add response to the output window. Application.Current.Dispatcher.BeginInvoke( new Action(() => pingItem.AddHistory(pingOutput.ToString()))); // If logging is enabled, write the response to a file. if (ApplicationOptions.LogOutput && ApplicationOptions.LogPath.Length > 0) { var index = pingItem.Hostname.IndexOf(':'); var hostname = (index > 0) ? pingItem.Hostname.Substring(0, index) : pingItem.Hostname; var logPath = $@"{ApplicationOptions.LogPath}\{hostname}.txt"; using (System.IO.StreamWriter outputFile = new System.IO.StreamWriter(@logPath, true)) { outputFile.WriteLine(pingOutput.ToString().Insert(1, DateTime.Now.ToShortDateString() + " ")); } } }
public HttpResponseMessage Post([FromBody] PingItem item) { try { var sc = BlogService.LoadPingServices(); if (!sc.Contains(item.ServiceUrl)) { sc.Add(item.ServiceUrl); } BlogService.SavePingServices(sc); var pings = new List <PingItem>(); foreach (var s in sc) { pings.Add(new PingItem { IsChecked = false, ServiceUrl = s }); } return(Request.CreateResponse(HttpStatusCode.Created, pings)); } catch (UnauthorizedAccessException) { return(Request.CreateResponse(HttpStatusCode.Unauthorized, Resources.labels.notAuthorized)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
private void HandlePingResponse(object sender, CTCPMessage e) { if (e.Command == "PING") { listLock.EnterReadLock(); PingItem pingItem = pingList.Find(item => item.Nick == e.Sender.Nickname); listLock.ExitReadLock(); if (pingItem != null) { DateTime curTime = DateTime.Now; DateTime prevTime = pingItem.Timestamp; TimeSpan difTime = curTime.Subtract(prevTime); string timeString = string.Empty; if (difTime.Days > 0) { timeString += difTime.Days.ToString(); timeString += (difTime.Days == 1) ? " Day, " : " Days, "; } if (difTime.Hours > 0) { timeString += difTime.Hours.ToString(); timeString += (difTime.Hours == 1) ? " Hour, " : " Hours, "; } if (difTime.Minutes > 0) { timeString += difTime.Minutes.ToString(); timeString += (difTime.Minutes == 1) ? " Minute, " : " Minutes, "; } if (difTime.Seconds > 0) { timeString += difTime.Seconds.ToString(); timeString += (difTime.Seconds == 1) ? " Second, " : " Seconds, "; } if (difTime.Milliseconds > 0) { timeString += difTime.Milliseconds.ToString(); timeString += (difTime.Milliseconds == 1) ? " Millisecond" : " Milliseconds"; } switch (pingItem.MessageType) { case MessageType.Channel: Bot.IRC.Command.SendPrivateMessage(pingItem.Location, string.Format("{0}, your ping is {1}", pingItem.Nick, timeString)); break; case MessageType.Notice: Bot.IRC.Command.SendNotice(pingItem.Nick, string.Format("Your ping is {0}", timeString)); break; case MessageType.Query: Bot.IRC.Command.SendPrivateMessage(pingItem.Nick, string.Format("Your ping is {0}", timeString)); break; } listLock.EnterWriteLock(); pingList.RemoveAll(item => item.Nick == pingItem.Nick); listLock.ExitWriteLock(); } } }
public EditAliasWindow(PingItem pingItem) { InitializeComponent(); Header.Text = "Alias for: " + pingItem.Hostname; MyAlias.Text = pingItem.Alias; MyAlias.SelectAll(); _CurrentPingItem = pingItem; // Set initial focus to text box. Loaded += (sender, e) => MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); }
public EditAliasWindow(string hostname, string alias) { InitializeComponent(); Header.Text = "Alias for: " + hostname; MyAlias.Text = alias; MyAlias.SelectAll(); _CurrentPingItem = new PingItem { Hostname = hostname, Alias = alias }; // Set initial focus to text box. Loaded += (sender, e) => MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); }
private void PingHost() { IPAddress ipAddress; var hostsList = new List <string>(); if (IPAddress.TryParse(this.address, out ipAddress)) { ipAddress = ipAddress.SetLastOctetTo(0); for (int i = 0; i < 255; i++) { ipAddress = NetworkUtils.IncrementIpAddress(ipAddress); hostsList.Add(ipAddress.ToString()); } var uiContext = SynchronizationContext.Current; try { Task.Run(() => { foreach (var result in hostsList .AsParallel().WithDegreeOfParallelism(64).Select(site => new { site, p = new Ping().Send(site) }).Select( @t => new { @t.site, Result = @t.p.Status, Time = @t.p.RoundtripTime })) { var item = new PingItem { Host = result.site, Result = result.Result, Time = result.Time }; Logger.Info($" Ping Item {result}"); uiContext.Send(x => this.PingItemCollection.Add(item), null); } }); } catch (OperationCanceledException exception) { Logger.Info($" Operation was cancelled. {exception.Message}"); } catch (Exception exception) { Logger.Info(exception); } } // NetworkUtils.PingHost(this.address); }
public void PingStartStop(PingItem pingItem) { if (string.IsNullOrEmpty(pingItem.Hostname)) { return; } if (!pingItem.IsActive) { pingItem.IsActive = true; if (pingItem.PingBackgroundWorker != null) { pingItem.PingBackgroundWorker.CancelAsync(); } pingItem.PingStatisticsText = string.Empty; pingItem.History = new ObservableCollection <string>(); pingItem.AddHistory($"*** Pinging {pingItem.Hostname}:"); pingItem.PingBackgroundWorker = new BackgroundWorker(); pingItem.PingResetEvent = new AutoResetEvent(false); if (pingItem.Hostname.Count(f => f == ':') == 1) { pingItem.PingBackgroundWorker.DoWork += new DoWorkEventHandler(backgroundThread_PerformTcpProbe); } else { pingItem.PingBackgroundWorker.DoWork += new DoWorkEventHandler(backgroundThread_PerformIcmpProbe); } pingItem.PingBackgroundWorker.WorkerSupportsCancellation = true; pingItem.PingBackgroundWorker.WorkerReportsProgress = true; pingItem.PingBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundThread_ProgressChanged); pingItem.PingBackgroundWorker.RunWorkerAsync(pingItem); } else { pingItem.PingBackgroundWorker.CancelAsync(); pingItem.PingResetEvent.WaitOne(); pingItem.Status = PingStatus.Inactive; pingItem.IsActive = false; } RefreshGlobalStartStop(); }
public HttpResponseMessage Post([FromBody] PingItem item) { var sc = BlogService.LoadPingServices(); if (!sc.Contains(item.ServiceUrl)) { sc.Add(item.ServiceUrl); } BlogService.SavePingServices(sc); var pings = new List <PingItem>(); foreach (var s in sc) { pings.Add(new PingItem { IsChecked = false, ServiceUrl = s }); } return(Request.CreateResponse(HttpStatusCode.Created, pings)); }
public override void ParseCommand(CommandMessage command) { Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command)); if (foundCommand.Name == "Ping Me") { int epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; PingItem tmpItem = new PingItem(); tmpItem.Nick = command.Nick.Nickname; tmpItem.Location = command.Location; tmpItem.MessageType = command.MessageType; tmpItem.Timestamp = DateTime.Now; listLock.EnterWriteLock(); if (pingList.Exists(item => item.Nick == command.Nick.Nickname)) { pingList.RemoveAll(item => item.Nick == command.Nick.Nickname); } pingList.Add(tmpItem); listLock.ExitWriteLock(); Bot.IRC.Command.SendCTCPMessage(command.Nick.Nickname, "PING", epoch.ToString()); } }
public EditAliasWindow(PingItem pingItem) : this(pingItem.Hostname, pingItem.Alias) { }
public void DisplayIcmpReply(PingItem pingItem) { if (pingItem.Reply == null) { return; } if (pingItem.PingBackgroundWorker.CancellationPending) { return; } var pingOutput = new StringBuilder($"[{DateTime.Now.ToLongTimeString()}] "); // Read the status code of the ping response. switch (pingItem.Reply.Status) { case IPStatus.Success: pingOutput.Append("Reply from "); pingOutput.Append(pingItem.Reply.Address.ToString()); if (pingItem.Reply.RoundtripTime < 1) { pingOutput.Append(" [<1ms]"); } else { pingOutput.Append($" [{pingItem.Reply.RoundtripTime} ms]"); } break; case IPStatus.DestinationHostUnreachable: pingOutput.Append("Reply [Host unreachable]"); break; case IPStatus.DestinationNetworkUnreachable: pingOutput.Append("Reply [Network unreachable]"); break; case IPStatus.DestinationUnreachable: pingOutput.Append("Reply [Unreachable]"); break; case IPStatus.TimedOut: pingOutput.Append("Request timed out."); break; default: pingOutput.Append(pingItem.Reply.Status.ToString()); break; } // Add response to the output window. Application.Current.Dispatcher.BeginInvoke( new Action(() => pingItem.AddHistory(pingOutput.ToString()))); // If logging is enabled, write the response to a file. if (ApplicationOptions.LogOutput && ApplicationOptions.LogPath.Length > 0) { var logPath = $@"{ApplicationOptions.LogPath}\{pingItem.Hostname}.txt"; using (System.IO.StreamWriter outputFile = new System.IO.StreamWriter(@logPath, true)) { outputFile.WriteLine(pingOutput.ToString().Insert(1, DateTime.Now.ToShortDateString() + " ")); } } }
public IsolatedPingWindow(PingItem pingItem) { InitializeComponent(); pingItem.IsolatedWindow = this; DataContext = pingItem; }