自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

細化autotelnet的實現

網絡 網絡管理
下面我們來對autotelnet的具體代碼進行一下介紹。首先是SHELL的實現,其次是Expect的代碼,最后是Python來實現。

對于Telnet,我們可以用多種方法來實現。這里我們就來介紹一下autotelnet的實現方法。那么具體內容請大家參考正文,希望對大家有所幫助。

一、Shell實現,文件名:autotelnet.sh,代碼如下:

  1. (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,代碼如下:

  1. #!/usr/bin/expect   
  2. set timeout 100   
  3. set TERM xterm   
  4. set SERVER "10.32.17.10"   
  5. set USER "root"   
  6. set PASSWD "123456"   
  7. spawn telnet   
  8. expect "telnet> "   
  9. send "open $SERVERr"   
  10. expect "Username:"   
  11. send "$USERr"   
  12. expect "Password:"   
  13. send "$PASSWDr"   
  14. expect "longjiang-zero>"   
  15. send "enr"   
  16. expect "Password:"   
  17. send "$PASSWDr"   
  18. expect "longjiang-zero#"   
  19. send "conf tr"   
  20. expect "longjiang-zero(config)#"   
  21. send "int fa0/1r"   
  22. expect "longjiang-zero(config-if)#"   
  23. send "switchport mode multir"   
  24. expect "longjiang-zero(config-if)#"   
  25. send "endr"   
  26. expect "longjiang-zero#"   
  27. send "exitr"   
  28. interact  

三、Python來實現,文件名:autotelnet.py,代碼如下:

  1. #!/usr/bin/python   
  2. import telnetlib   
  3. host = ''10.32.17.10''   
  4. user = ''root''   
  5. password = ''123456''   
  6. commands = [''en'',password,''conf t'',''int fa0/1'',''switchport mode multi'',''end'']   
  7. tn = telnetlib.Telnet(host)   
  8. tn.read_until("Username:")   
  9. tn.write(user + "n")   
  10. tn.read_until("Password:")   
  11. tn.write(password + "n")   
  12. for command in commands:   
  13. tn.write(command+''n'')   
  14. tn.write("exitn")   
  15. print tn.read_all()   
  16. print ''Finish!''  

 

責任編輯:佟健 來源: 網絡轉載
相關推薦

2010-07-19 13:49:52

autoTelnet

2009-01-04 16:50:54

2014-05-28 17:53:03

2015-08-19 17:30:29

暢享網

2013-10-25 14:22:08

SAP

2014-04-04 16:05:04

東華網智流量控制

2018-04-18 14:38:14

廣告

2010-11-18 11:22:00

流量管理網絡優(yōu)化深信服科技

2010-04-20 13:30:42

2010-04-16 13:41:14

Oracle表分區(qū)

2020-09-16 08:07:54

權限粒度Spring Secu

2013-03-11 15:14:53

網絡虛擬化企業(yè)網絡運維IP網絡技術

2010-04-22 12:46:55

Oracle hint

2014-11-12 09:05:49

2016-05-25 11:51:42

華西醫(yī)院易維幫助臺

2009-12-03 00:41:45

2022-06-20 14:29:16

權限按鈕動態(tài)管理

2009-12-17 10:58:38

代理路由器設置步驟

2021-07-19 18:28:30

AppGallery 運營

2014-05-09 10:03:09

上方花園
點贊
收藏

51CTO技術棧公眾號