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

分类: 系统管理   出处:iocblog整理  更新时间:2008-11-14   添加到收藏  

  一、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

[1] [2] 下一页


Tag: Shell ,telnet



文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。