今天就跟大家聊聊有關怎么在python中使用telnetlib備份交換機,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
1. 登錄方式和口令有好幾種,比較懶惰,通過不同列表以做區分,如果每個交換機口令都不相同的話,就需要額外處理了。
2. 交換機的配置文件也有多種類型,也是通過列表進行區分。
3. 有些交換機支持ftp和sftp,但測試發現有些雖然有相應的客戶端命令,但傳輸總有問題。也不能將每個交換機都配置為ftp服務器,不安全也不方便。最后采用tftp解決。tftp比較簡單,沒有辦法創建目錄以區分不同日期的備份。好在配置文件已經加入了日期做區分,馬馬虎虎可以運行了。
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()
看完上述內容,你們對怎么在python中使用telnetlib備份交換機有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創新互聯成都網站設計公司行業資訊頻道,感謝大家的支持。
另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
文章標題:怎么在python中使用telnetlib備份交換機-創新互聯
文章出自:http://www.hntjjpw.com/article10/ddiedo.html
成都網站建設公司_創新互聯,為您提供小程序開發、Google、微信小程序、做網站、標簽優化、用戶體驗
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯