private void ParseData(string data) { StringBuilder sb = new StringBuilder(); StringReader sr = new StringReader(data); sb.Append(sr.ReadLine()); if (PatternChecker.IsTraceComplete(sb.ToString()) && CheckIfCancel()) { Console.WriteLine("trace complete"); Dispatcher.Invoke(() => ClearGrid()); IsTraceComplete = true; return; } List <String> tempList = new List <string>(); MatchCollection matches = Regex.Matches(sb.ToString(), @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"); if (matches.Count > 0) { foreach (var item in matches) { tempList.Add(item.ToString()); } } if (tempList.Count > 0) { string tempHost = tempList[0]; routeList.Add(tempHost); } }
private void ParseData(string data, CancellationToken token) { StringBuilder sb = new StringBuilder(); StringReader sr = new StringReader(data); sb.Append(sr.ReadToEnd()); if (PatternChecker.IsTraceComplete(sb.ToString()) && token.IsCancellationRequested == false) { Dispatcher.Invoke(() => ClearGrid()); IsTraceComplete = true; return; } List <String> tempList = new List <string>(); int dataValue = 0; //Captures IPs and excludes latency and non-numerical IPs for (int i = 0; i < sb.Length; i++) { if (token.IsCancellationRequested) { return; } if (sb[i] != ' ' && sb[i] != '<' && sb[i] != '[') { StringBuilder sb2 = new StringBuilder(); while (sb[i] != '*') { if (token.IsCancellationRequested) { return; } if (sb.Length > i + 1) { if (sb[i + 1] == ' ') { if (dataValue == 7 || dataValue == 8) { if (sb[i] != ']') { sb2.Append(sb[i].ToString()); } if (PatternChecker.IsValidIP(sb2.ToString())) { tempList.Add(sb2.ToString()); } } dataValue += 1; break; } if (dataValue == 7 || dataValue == 8) { sb2.Append(sb[i].ToString()); } i++; } } if (sb[i] == '*') { if (dataValue == 1 || dataValue == 3) { dataValue += 2; } } } } if (tempList.Count > 0) { string tempHost = tempList[0]; routeList.Add(tempHost); } }