private void UpdateRecords() { var records = new Dictionary <string, StatisticsRecord>(); UpdateRecordsState state = new UpdateRecordsState(); int serverCount = _controller.GetCurrentConfiguration().configs.Count; state.counter = serverCount; bool isPing = Config.Ping; for (int i = 0; i < serverCount; i++) { try { var server = _controller.GetCurrentConfiguration().configs[i]; var id = server.Identifier(); List <int> inboundSpeedRecords = null; List <int> outboundSpeedRecords = null; List <int> latencyRecords = null; _inboundSpeedRecords.TryGetValue(id, out inboundSpeedRecords); _outboundSpeedRecords.TryGetValue(id, out outboundSpeedRecords); _latencyRecords.TryGetValue(id, out latencyRecords); StatisticsRecord record = new StatisticsRecord(id, inboundSpeedRecords, outboundSpeedRecords, latencyRecords); /* duplicate server identifier */ if (records.ContainsKey(id)) { records[id] = record; } else { records.Add(id, record); } if (isPing) { // FIXME: on ping completed, every thing could be asynchrously changed. // focus on: Config/ RawStatistics MyPing ping = new MyPing(server, Repeat); ping.Completed += ping_Completed; ping.Start(new PingState { state = state, record = record }); } else if (!record.IsEmptyData()) { AppendRecord(id, record); } } catch (Exception e) { Logging.Debug("config changed asynchrously, just ignore this server"); } } if (!isPing) { Save(); FilterRawStatistics(); } }
private static void Main(string[] args) { // var erg = mp.GetPingTime("8.8.8.8"); string line = " "; StreamReader file = new StreamReader(@"D:\Work\remotedesktop\Filterwork\All.txt"); MyPing mp = new MyPing(x => { Queue.Enqueue(x); //Console.WriteLine($"Online: {x.ToString()}"); }); new Thread(WriteIt) { IsBackground = true, Name = "WriteThread" }.Start(); while (!string.IsNullOrEmpty((line = file.ReadLine()))) { var ipInfo = ParseIpString(line); if (ipInfo.Item1) { mp.EnqueueIP(ipInfo.Item2.Item1); } // } Console.WriteLine("Enqueued"); Console.ReadLine(); Ping pingSender = new Ping(); PingOptions options = new PingOptions(); // Benutze den Standard TTL Wert (Time To Live) der bei 128ms liegt, // aber ändere das Fragmentationsverhalten. options.DontFragment = true; // Erzeuge einen Puffer mit der Länge von 32 Bytes // die versendet werden sollen. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; PingReply reply = pingSender.Send(args[0], timeout, buffer, options); if (reply.Status == IPStatus.Success) { Console.WriteLine("Address: {0}", reply.Address.ToString()); Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime); Console.WriteLine("Time to live: {0}", reply.Options.Ttl); Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment); Console.WriteLine("Buffer size: {0}", reply.Buffer.Length); } }
private void UpdateRecords() { var records = new Dictionary <string, StatisticsRecord>(); UpdateRecordsState state = new UpdateRecordsState(); state.counter = _controller.GetCurrentConfiguration().configs.Count; foreach (var server in _controller.GetCurrentConfiguration().configs) { var id = server.Identifier(); List <int> inboundSpeedRecords = null; List <int> outboundSpeedRecords = null; List <int> latencyRecords = null; _inboundSpeedRecords.TryGetValue(id, out inboundSpeedRecords); _outboundSpeedRecords.TryGetValue(id, out outboundSpeedRecords); _latencyRecords.TryGetValue(id, out latencyRecords); StatisticsRecord record = new StatisticsRecord(id, inboundSpeedRecords, outboundSpeedRecords, latencyRecords); /* duplicate server identifier */ if (records.ContainsKey(id)) { records[id] = record; } else { records.Add(id, record); } if (Config.Ping) { MyPing ping = new MyPing(server, Repeat); ping.Completed += ping_Completed; ping.Start(new PingState { state = state, record = record }); } else if (!record.IsEmptyData()) { AppendRecord(id, record); } } if (!Config.Ping) { Save(); FilterRawStatistics(); } }
private void Ping() { while (pinging) //pings forever until after pinging is set to false. { //PingReply reply = p.Send(ip, 0, bytes); MyPing ping = delegate() { var pingSender = new Ping(); PingReply reply = pingSender.Send(ip, 1, bytes); }; var asyncResults = new IAsyncResult[0x200]; for (int i = 1; i < 0x200; i++) { asyncResults[i] = ping.BeginInvoke(null, null); } for (int i = 1; i < 0x200; i++) { ping.EndInvoke(asyncResults[i]); } } }
private void UpdateRecords() { var records = new Dictionary<string, StatisticsRecord>(); UpdateRecordsState state = new UpdateRecordsState(); state.counter = _controller.GetCurrentConfiguration().configs.Count; foreach (var server in _controller.GetCurrentConfiguration().configs) { var id = server.Identifier(); List<int> inboundSpeedRecords = null; List<int> outboundSpeedRecords = null; List<int> latencyRecords = null; _inboundSpeedRecords.TryGetValue(id, out inboundSpeedRecords); _outboundSpeedRecords.TryGetValue(id, out outboundSpeedRecords); _latencyRecords.TryGetValue(id, out latencyRecords); StatisticsRecord record = new StatisticsRecord(id, inboundSpeedRecords, outboundSpeedRecords, latencyRecords); /* duplicate server identifier */ if (records.ContainsKey(id)) records[id] = record; else records.Add(id, record); if (Config.Ping) { MyPing ping = new MyPing(server, Repeat); ping.Completed += ping_Completed; ping.Start(new PingState { state = state, record = record }); } else if (!record.IsEmptyData()) { AppendRecord(id, record); } } if (!Config.Ping) { Save(); FilterRawStatistics(); } }
private void ping_Completed(object sender, MyPing.CompletedEventArgs e) { PingState pingState = (PingState)e.UserState; UpdateRecordsState state = pingState.state; Server server = e.Server; StatisticsRecord record = pingState.record; record.SetResponse(e.RoundtripTime); if (!record.IsEmptyData()) { AppendRecord(server.Identifier(), record); } Logging.Debug($"Ping {server.FriendlyName()} {e.RoundtripTime.Count} times, {(100 - record.PackageLoss * 100)}% packages loss, min {record.MinResponse} ms, max {record.MaxResponse} ms, avg {record.AverageResponse} ms"); if (Interlocked.Decrement(ref state.counter) == 0) { Save(); FilterRawStatistics(); } }