今天就跟大家聊聊有關(guān)怎么在python中使用telnetlib備份交換機(jī),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
1. 登錄方式和口令有好幾種,比較懶惰,通過(guò)不同列表以做區(qū)分,如果每個(gè)交換機(jī)口令都不相同的話,就需要額外處理了。
2. 交換機(jī)的配置文件也有多種類型,也是通過(guò)列表進(jìn)行區(qū)分。
3. 有些交換機(jī)支持ftp和sftp,但測(cè)試發(fā)現(xiàn)有些雖然有相應(yīng)的客戶端命令,但傳輸總有問(wèn)題。也不能將每個(gè)交換機(jī)都配置為ftp服務(wù)器,不安全也不方便。最后采用tftp解決。tftp比較簡(jiǎn)單,沒有辦法創(chuàng)建目錄以區(qū)分不同日期的備份。好在配置文件已經(jīng)加入了日期做區(qū)分,馬馬虎虎可以運(yùn)行了。
import telnetlib,sys from datetime import date today=date.today() print(today) ipaddrset1=['192.168.1.19','192.168.1.29','192.168.1.59'] ipaddrset2=['192.168.1.39','192.168.1.49','192.168.1.69','192.168.1.56','192.168.1.6','192.168.1.9','192.168.1.24', '192.168.1.72','192.168.1.73','192.168.1.74','192.168.1.75','192.168.1.76','192.168.1.41','192.168.1.16','192.168.1.32',] ipaddrset3=['192.168.1.51','192.168.1.52','192.168.1.53','192.168.1.54','192.168.1.55', '192.168.1.15','192.168.1.16','192.168.1.22','192.168.1.23','192.168.1.25','192.168.1.26','192.168.1.27', '192.168.1.28','192.168.1.7'] hostname='192.168.8.201' tn=telnetlib.Telnet(hostname) print(tn.read_until(b'Username:').decode('ascii')) tn.write(b'**********\n') print(tn.read_until(b'Password:').decode('ascii')) tn.write(b'************\n') print(tn.read_until(b'>').decode('ascii')) for ipaddr in ipaddrset1: telnet_dest="telnet "+ipaddr tn.write(telnet_dest.encode('ascii')+b'\n') tn.read_until(b'Password:').decode('ascii') tn.write(b'**********\n') tn.read_until(b'>').decode('ascii') tn.write(b'dir\n') tn.read_until(b'>').decode('ascii') fn=str(today)+"_"+str(ipaddr)+"_vrpcfg.zip \n" cmdli="tftp 192.168.5.33 put vrpcfg.zip " +str(fn) tn.write(cmdli.ede('ascii')) tmp=tn.read_until(b'>').decode('ascii') if "successfully" in tmp: print(str(ipaddr)+" backup successfully!") else: print(str(ipaddr)+" backup NOT successfully!") tn.write(b'quit\n') tn.read_until(b'>') for ipaddr in ipaddrset2: telnet_dest="telnet "+ipaddr tn.write(telnet_dest.encode('ascii')+b'\n') tn.read_until(b'Password:').decode('ascii') tn.write(b'**********\n') tn.read_until(b'>').decode('ascii') tn.write(b'dir\n') tn.read_until(b'>').decode('ascii') fn=str(today)+"_"+str(ipaddr)+"_startup.cfg \n" cmdli="tftp 192.168.5.33 put startup.cfg " +str(fn) tn.write(cmdli.encode('ascii')) tmp=tn.read_until(b'>').decode('ascii') if "successfully" in tmp: print(str(ipaddr)+" backup successfully!") else: print(str(ipaddr)+" backup NOT successfully!") tn.write(b'quit\n') tn.read_until(b'>') for ipaddr in ipaddrset3: telnet_dest="telnet "+ipaddr tn.write(telnet_dest.encode('ascii')+b'\n') tn.read_until(b'Password:').decode('ascii') tn.write(b'************\n') tn.read_until(b'>').decode('ascii') tn.write(b'dir\n') tn.read_until(b'>').decode('ascii') fn=str(today)+"_"+str(ipaddr)+"_startup.cfg \n" cmdli="tftp 192.168.5.33 put startup.cfg " +str(fn) tn.write(cmdli.encode('ascii')) tmp=tn.read_until(b'>').decode('ascii') if "successfully" in tmp: print(str(ipaddr)+" backup successfully!") else: print(str(ipaddr)+" backup NOT successfully!") tn.write(b'quit\n') tn.read_until(b'>') tn.write(b'exit\n') tn.close()
看完上述內(nèi)容,你們對(duì)怎么在python中使用telnetlib備份交換機(jī)有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道,感謝大家的支持。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
文章標(biāo)題:怎么在python中使用telnetlib備份交換機(jī)-創(chuàng)新互聯(lián)
文章出自:http://chinadenli.net/article10/ddiedo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、Google、微信小程序、做網(wǎng)站、標(biāo)簽優(yōu)化、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容