标题: [转载代码] PowerShell中使用telnet连接交换机 [打印本页]
作者: DAIC 时间: 2013-9-16 21:56 标题: PowerShell中使用telnet连接交换机
- $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
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |