Skip to content

Instantly share code, notes, and snippets.

@lselden
Created February 26, 2014 22:20
Show Gist options
  • Save lselden/9239884 to your computer and use it in GitHub Desktop.
Save lselden/9239884 to your computer and use it in GitHub Desktop.
try {
$remoteHost = Read-Host "Enter IP / Hostname"
$port = 23
write-host "Connecting to $remoteHost on port $port"
$socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port)
if($socket -eq $null) { return; }
$stream = $socket.GetStream()
$writer = new-object System.IO.StreamWriter($stream)
$buffer = new-object System.Byte[] 1024
$encoding = new-object System.Text.AsciiEncoding
while($true) {
start-sleep -m 500
while($stream.DataAvailable) {
$read = $stream.Read($buffer, 0, 1024)
write-host -n ($encoding.GetString($buffer, 0, $read))
}
$command = read-host
$writer.WriteLine($command)
$writer.Flush()
}
}
finally {
$writer.Close()
$stream.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment