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

Python telnet編程代碼

網(wǎng)絡(luò) 網(wǎng)絡(luò)管理
下面我們簡(jiǎn)單介紹一下Python telnet的實(shí)現(xiàn)過程,那么具體的代碼內(nèi)容我們也做了詳細(xì)介紹,希望大家能夠得到參考。

在進(jìn)行telnet的相關(guān)設(shè)置中,我們通常會(huì)接觸其他語言來進(jìn)行編輯。這里我們主要介紹一下用腳本來實(shí)現(xiàn)這方面的操作。包括Python telnet的實(shí)現(xiàn)過程。那么具體的內(nèi)容請(qǐng)大家來看文章內(nèi)容吧。

一、Shell實(shí)現(xiàn),文件名: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來實(shí)現(xiàn),文件名: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 telnet的實(shí)現(xiàn),文件名: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!'' 

到這里我們就已經(jīng)完成了Python telnet的實(shí)現(xiàn)過程了。

責(zé)任編輯:佟健 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-07-17 00:55:48

PHP Telnet

2010-07-17 00:53:50

CMD Telnet

2022-05-26 07:53:33

Python代碼編程語言

2010-07-15 10:58:12

啟動(dòng)telnet服務(wù)

2010-07-22 12:54:15

開啟telnet服務(wù)

2010-07-15 11:24:17

telnet服務(wù)

2018-07-23 08:19:26

編程語言Python工具

2010-07-14 17:46:40

Telnet Tool

2010-07-22 10:23:19

2017-04-06 16:20:27

Python趣味代碼編程

2024-06-19 08:49:48

2024-01-22 08:20:40

Python編程語言代碼陷阱

2010-07-20 14:55:16

Telnet端口

2009-12-01 13:35:39

Telnet服務(wù)

2024-11-04 16:08:21

2024-05-31 13:14:05

2024-11-29 08:00:00

代碼安全代碼Python

2010-07-26 13:03:23

Telnet會(huì)話

2010-07-26 13:44:33

Ubuntu teln

2010-07-25 14:37:40

telnet命令
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)