Created
February 26, 2014 22:20
-
-
Save lselden/9239884 to your computer and use it in GitHub Desktop.
Telnet using PowerShell (http://brianreiter.org/2011/06/08/cool-powershell-script-replicates-telnet/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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