void ExtractAccessListData(OutputReport report, string text) { report.LineType = AccessListIdentifier; var words = text.Split(' ').ToList(); var startPointer = words.FindIndex(x => x.Contains("eq")); var endPointer = words.FindIndex(x => x.Contains("(hitcnt=")); if (endPointer > 0 && startPointer > 0) { var port = words[endPointer - 1]; if (!port.Contains("255.")) report.Port = port; } ExtractIPs(report, text); }
void ExtractIPs(OutputReport report, string value) { string pattern = null; pattern = @"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"; //This one actually works var words = value.Split(' '); MatchCollection ips = Regex.Matches(value, pattern); for (int i = 0; i < ips.Count; i++) { var ipValue = ips[i].Value; if (!ipValue.Contains("255")) report.IPAddresses.Add(ipValue); } }
List<string> ProcessFileData(List<string> fileData) { var reports = new List<OutputReport>(); var result = new List<string>(); //result.Add(OutputReport.GenerateHeaderLine()); foreach (var line in fileData) { var report = new OutputReport(); var isAccessList = line.Contains(AccessListIdentifier); var text = line.Replace("-", " ").Replace("_", " "); if (isAccessList) ExtractAccessListData(report, text); //else // ExtractIPs(report, text); if (string.IsNullOrEmpty(report.Port) && report.IPAddresses.Count == 0) continue; reports.Add(report); } int ipColumnCount = reports.Select(x => x.IPAddresses.Count).Max(); result.Add(OutputReport.GenerateHeaderLine(ipColumnCount)); reports.ForEach(x => result.Add(x.ToString())); return result; }