Guest User

Untitled

a guest
Jan 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. public class DumpPcap
  2. {
  3. public int _interfaceNumber;
  4. public string _pcapPath;
  5. public string _dumPcapPath = @"C:Program FilesWiresharkdumpcap.exe";
  6.  
  7. public DumpPcap(int interfaceNumber, string pcapPath)
  8. {
  9. _interfaceNumber = interfaceNumber;
  10. _pcapPath = pcapPath;
  11. }
  12.  
  13. public void startTheCapture()
  14. {
  15. List<string> stList = new List<string>();
  16. ProcessStartInfo process = new ProcessStartInfo(_dumPcapPath);
  17. process.Arguments = string.Format("-i " + _interfaceNumber + " -s 65535 -w " + _pcapPath);
  18. process.WindowStyle = ProcessWindowStyle.Hidden;
  19. process.RedirectStandardOutput = true;
  20. process.RedirectStandardError = true;
  21. process.CreateNoWindow = true;
  22. process.UseShellExecute = false;
  23. process.ErrorDialog = false;
  24. Process dumpcap = Process.Start(process);
  25. StreamReader reader = dumpcap.StandardOutput;
  26. //dumpcap.WaitForExit(100000);
  27.  
  28. while (!reader.EndOfStream)
  29. {
  30. stList.Add(reader.ReadLine());
  31. }
  32. }
  33. }
  34.  
  35. List<string> stList = new List<string>();
  36.  
  37. var process = new Process();
  38. process.StartInfo.FileName = _dumPcapPath;
  39. process.StartInfo.Arguments =
  40. string.Format("-i " + _interfaceNumber + " -s 65535 -w " + _pcapPath);
  41. process.Startinfo.WindowStyle = ProcessWindowStyle.Hidden;
  42. process.Startinfo.RedirectStandardOutput = true;
  43. process.Startinfo.RedirectStandardError = true;
  44. process.Startinfo.CreateNoWindow = true;
  45. process.Startinfo.UseShellExecute = false;
  46. process.Startinfo.ErrorDialog = false;
  47.  
  48. // capture the data received event here...
  49. process.OutputDataReceived +=
  50. new DataReceivedEventHandler(process_OutputDataReceived);
  51.  
  52. process.Start();
  53. process.BeginOutputReadLine();
  54.  
  55.  
  56. private void process_OutputDataReceived(object sender, DataReceivedEventArgs arg)
  57. {
  58. // arg.Data contains the output data from the process...
  59. }
Add Comment
Please, Sign In to add comment