Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Telnet ($RemoteHost, $Port, $message) {
- try {
- ## Open the socket, and connect to the computer on the specified port
- "Attempting to connect to $RemoteHost..."
- $socket = new-object System.Net.Sockets.TcpClient($remoteHost,$Port)
- if($socket -eq $null) {
- "Unable to connect to $remotehost" | Out-file $log
- exit
- }
- $stream = $socket.GetStream()
- $writer = new-object System.IO.StreamWriter($stream)
- $buffer = new-object System.Byte[] 1024
- $encoding = new-object System.Text.AsciiEncoding
- #Write the command to the remote host
- $writer.WriteLine($message)
- $writer.Flush()
- do {
- $currentTime
- #Allow data to buffer for a bit
- start-sleep -m 500
- #reads the stream and outputs it to the log
- $read = $stream.Read($buffer, 0, 1024)
- $result = ($encoding.GetString($buffer, 0, $read))
- $result | Out-File $messageLog
- }
- until($currentTime -ge (Get-Date "10:00pm"))
- }
- finally {
- ## Close the streams
- $writer.Close()
- $stream.Close()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement