- $remoteHost = "hostname"
- $port = 23
- $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
- function telnet($command){
- #$command = read-host
- $writer.WriteLine($command)
- $writer.Flush()
- start-sleep -m 500
- while($stream.DataAvailable){
- $read = $stream.Read($buffer, 0, 1024)
- write-host -n ($encoding.GetString($buffer, 0, $read))
- }
- }
- #hostname:要连接的交换机ip输入telnet “你要输入的指令如用户名和密码” #该功能主要的意义是可以通过轮循来同时配置多台设备.
复制代码 http://hi.baidu.com/shrekzz/item/81cff5a74bf9192e8819d3fe |