Advertisement
rafelivgi

Untitled

Feb 28th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. $TCPServer = "localhost"
  2. $TCPPort = "8080"
  3.  
  4. $tcpConnection = New-Object System.Net.Sockets.TcpClient($TCPServer, $TCPPort)
  5. $tcpStream = $tcpConnection.GetStream()
  6. $reader = New-Object System.IO.StreamReader($tcpStream)
  7. $writer = New-Object System.IO.StreamWriter($tcpStream)
  8. $writer.AutoFlush = $true
  9.  
  10. while ($tcpConnection.Connected)
  11. {
  12. while ($tcpStream.DataAvailable)
  13. {
  14. $reader.ReadLine()
  15. }
  16.  
  17. if ($tcpConnection.Connected)
  18. {
  19. Write-Host -NoNewline "prompt> "
  20. $command = Read-Host
  21.  
  22. if ($command -eq "escape")
  23. {
  24. break
  25. }
  26.  
  27. $writer.WriteLine($command) | Out-Null
  28. }
  29. }
  30.  
  31. $reader.Close()
  32. $writer.Close()
  33. $tcpConnection.Close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement