public DigInfo getDigResult(string strDomainToTest) { DigInfo dinf = new DigInfo(); Process p = new Process(); string strPathToUse = $"{strDigPath}{System.IO.Path.DirectorySeparatorChar}dig.exe"; string strWorkingDir = strDigPath; if (strFullDigPath != null) { strPathToUse = strFullDigPath; strWorkingDir = System.Reflection.Assembly.GetExecutingAssembly().Location; } p.StartInfo = new ProcessStartInfo(strPathToUse) { RedirectStandardInput = false, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = strWorkingDir, LoadUserProfile = false, WindowStyle = ProcessWindowStyle.Hidden, Arguments = $"{strDomainToTest} @{strDNSServer}" }; parseMode pm = parseMode.status; bool bStarted = p.Start(); while (!p.StandardOutput.EndOfStream) { var strLine = p.StandardOutput.ReadLine(); if (bDigResult && strLine != null && strLine.Length > 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(strLine); Console.ResetColor(); } if (parseMode.status == pm && strLine.Length > 2) { MatchCollection mc = Regex.Matches(strLine, strRegexStatus); if (mc.Count > 0) { dinf.strStatus = mc[0].Groups[1].Value; pm = parseMode.waitanswer; } } else if (parseMode.waitanswer == pm) { if (strLine.IndexOf("ANSWER SECTION") > 0) { pm = parseMode.answer; } } else if (parseMode.answer == pm) { if (strLine.Length < 1 || strLine.Trim().Length < 1) { p.StandardOutput.ReadToEnd(); break; } MatchCollection mc = Regex.Matches(strLine, strRegexAnswer); if (mc.Count > 4) { DigAnswerRecord da = new DigAnswerRecord() { strRecord = mc[4].Value.TrimEnd(new char[] { '.' }), strType = mc[3].Value.TrimEnd(new char[] { '.' }), strStart = mc[0].Value.TrimEnd(new char[] { '.' }), }; dinf.lstRecord.Add(da); } } } p.WaitForExit(); Console.WriteLine("[+] Dig is done"); return(dinf); }
public DigInfo getDigResult(string strDomainToTest) { DigInfo dinf = new DigInfo(); Process p = new Process(); p.StartInfo = new ProcessStartInfo($"{strDigPath}\\dig.exe") { RedirectStandardInput = false, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = strDigPath, LoadUserProfile = false, WindowStyle = ProcessWindowStyle.Hidden, Arguments = $"{strDomainToTest} @{strDNSServer}" }; parseMode pm = parseMode.status; bool bStarted = p.Start(); while (!p.StandardOutput.EndOfStream) { var strLine = p.StandardOutput.ReadLine(); if (parseMode.status == pm && strLine.Length > 2) { MatchCollection mc = Regex.Matches(strLine, strRegexStatus); if (mc.Count > 0) { dinf.strStatus = mc[0].Groups[1].Value; pm = parseMode.waitanswer; } } else if (parseMode.waitanswer == pm) { if (strLine.IndexOf("ANSWER SECTION") > 0) { pm = parseMode.answer; } } else if (parseMode.answer == pm) { if (strLine.Length < 1 || strLine.Trim().Length < 1) { p.StandardOutput.ReadToEnd(); break; } MatchCollection mc = Regex.Matches(strLine, strRegexAnswer); if (mc.Count > 4) { DigAnswerRecord da = new DigAnswerRecord() { strRecord = mc[4].Value.TrimEnd(new char[] { '.' }), strType = mc[3].Value.TrimEnd(new char[] { '.' }), strStart = mc[0].Value.TrimEnd(new char[] { '.' }), }; dinf.lstRecord.Add(da); } } } p.WaitForExit(); Console.WriteLine("[+] Dig is done"); return(dinf); }