快捷搜索:   nginx

Linux操作系统下三种方式实现自动Telnet

  一、Shell实现,文件名:autotelnet.sh,代码如下:

  (sleep 1;echo "root";sleep 1;echo "123456";sleep 1;echo "en";sleep 1;echo "1qazse4";sleep 1;echo "conf t";sleep 1;echo "int fa0/1";sleep 1;echo "switchport mode multi";sleep 1;echo "end";sleep 1;echo "exit") | telnet 10.32.17.10

  二、Expect来实现,文件名:autotelnet.exp,代码如下:

  #!/usr/bin/expect

  set timeout 100

  set TERM xterm

  set SERVER "10.32.17.10"

  set USER "root"

  set PASSWD "123456"

  spawn telnet

  expect "telnet> "

  send "open $SERVERr"

  expect "Username:"

  send "$USERr"

  expect "Password:"

  send "$PASSWDr"

  expect "longjiang-zero>"

  send "enr"

  expect "Password:"

  send "$PASSWDr"

  expect "longjiang-zero#"

  send "conf tr"

  expect "longjiang-zero(config)#"

  send "int fa0/1r"

  expect "longjiang-zero(config-if)#"

  send "switchport mode multir"

  expect "longjiang-zero(config-if)#"

  send "endr"

  expect "longjiang-zero#"

  send "exitr"

  interact

 [2] 下一页

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论