Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- using static System.Console;
- using ShellProgressBar;
- using System.ComponentModel;
- namespace OTPOPS_NetDiag
- {
- public class TraceRoute
- {
- static readonly string traceRouteExeecutblePath = "TRACERT.EXE";
- static int tickCount = 30;
- static int runtimes = 0;
- static ProgressBarOptions options = new ProgressBarOptions
- {
- BackgroundCharacter = '○',
- BackgroundColor = ConsoleColor.DarkBlue,
- ProgressCharacter = '●',
- ProgressBarOnBottom = true,
- ForegroundColor = ConsoleColor.White,
- ShowEstimatedDuration = true,
- EnableTaskBarProgress = true,
- CollapseWhenFinished = true,
- };
- static ProgressBar pbar;
- static int currentCursorLeft = CursorLeft;
- static int currentCursorTop = CursorTop;
- public static void GetTrace(string hostName)
- {
- string argumentsList = $"-d -4 -w 100 {hostName}";
- ProcessStartInfo processStartInfo = new ProcessStartInfo(traceRouteExeecutblePath, argumentsList)
- {
- UseShellExecute = false,
- LoadUserProfile = false,
- WindowStyle = ProcessWindowStyle.Hidden,
- StandardOutputEncoding = Encoding.UTF8,
- RedirectStandardOutput = true
- };
- Process process = new Process();
- process.StartInfo = processStartInfo;
- process.Start();
- WriteLine(process.StandardOutput.ReadToEnd());
- process.WaitForExit();
- //return null;
- }
- public static void GetTraceAsync(string hostName)
- {
- //* Create your Process
- string argumentsList = $"-d -4 -w 100 {hostName}";
- ProcessStartInfo processStartInfo = new ProcessStartInfo(traceRouteExeecutblePath, argumentsList)
- {
- UseShellExecute = false,
- LoadUserProfile = false,
- WindowStyle = ProcessWindowStyle.Hidden,
- StandardOutputEncoding = Encoding.UTF8,
- RedirectStandardOutput = true,
- RedirectStandardError = true
- };
- Process process = new Process();
- process.StartInfo = processStartInfo;
- //* Set your output and error (asynchronous) handlers
- process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
- process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
- //* Start process and handlers
- pbar = new ProgressBar(tickCount, "1", options);
- currentCursorLeft = CursorLeft;
- currentCursorTop = CursorTop;
- process.Start();
- process.BeginOutputReadLine();
- process.BeginErrorReadLine();
- process.WaitForExit();
- pbar.Tick(30, "Готово");
- pbar.Dispose();
- SetCursorPosition(currentCursorLeft, currentCursorTop + 3);
- }
- static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
- {
- pbar.Tick();
- WriteLine(outLine.Data);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement