python利用paramiko實(shí)現(xiàn)交換機(jī)巡檢的示例
直接上代碼
#-*- coding:UTF-8 -*- import paramiko import time starttime = time.strftime('%Y-%m-%d %T') start_info = "巡檢開始時(shí)間:"+str(starttime) cmd_filepath = r"d:\Python\py\xunjian\cmd.txt" cmd_file = open(cmd_filepath,"r") cmds = cmd_file.readlines() dev_filepath = r"d:\Python\py\xunjian\device_info.txt" dev_file = open(dev_filepath,"r") while 1: dev_info = dev_file.readline() if not dev_info : break else : devs = dev_info.split(',') ip = devs[0] username = devs[1] password = devs[2].strip() password = password.strip('\n') ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname = ip,username = username,password = password) print("成功連接",ip) command = ssh.invoke_shell() time.sleep(3) command.send('N\n') #該行非必須 command.send('screen-length 0 temporary\n') #取消分屏顯示 for cmd in cmds: command.send(cmd+'\n') time.sleep(5) output = command.recv(65535).decode() log = open(r"d:\Python\py\xunjian\\"+ip+".txt",'a') endtime = time.strftime('%Y-%m-%d %T') end_info = "巡檢結(jié)束時(shí)間:"+str(endtime) log.write(start_info+'\n\n'+output+'\n\n'+end_info) log.close() dev_file.close() #巡檢命令文檔cmd.txt display device display environment display alarm urgen display memory-usage display cpu-usage display logbuffer level 0 display logbuffer level 1 display logbuffer level 2 display logbuffer level 3 display logbuffer level 4 #設(shè)備信息 device_info.txt 192.168.10.11,admin,Huawei@123 192.168.10.12,admin,Huawei@123 192.168.10.13,admin,Huawei@123 192.168.10.14,admin,Huawei@123
以上就是python利用paramiko實(shí)現(xiàn)交換機(jī)巡檢的示例的詳細(xì)內(nèi)容,更多關(guān)于paramiko交換機(jī)巡檢的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
python引入requests報(bào)錯(cuò)could?not?be?resolved解決方案
這篇文章主要為大家介紹了python引入requests報(bào)錯(cuò)could?not?be?resolved解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05教你用Python為二年級(jí)的學(xué)生批量生成數(shù)學(xué)題
這兩天在學(xué)習(xí)pthon,正好遇到老師布置的暑假作業(yè),需要家長給還在出試卷,下面這篇文章主要給大家介紹了關(guān)于如何用Python為二年級(jí)的學(xué)生批量生成數(shù)學(xué)題的相關(guān)資料,需要的朋友可以參考下2023-02-02解決Numpy與Pytorch彼此轉(zhuǎn)換時(shí)的坑
這篇文章主要介紹了解決Numpy與Pytorch彼此轉(zhuǎn)換時(shí)的坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05CentOS下使用yum安裝python-pip失敗的完美解決方法
這篇文章主要介紹了CentOS下使用yum安裝python-pip失敗的完美解決方法,需要的朋友可以參考下2017-08-08Python 循環(huán)終止語句的三種方法小結(jié)
今天小編就為大家分享一篇Python 循環(huán)終止語句的三種方法小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06Python中三元運(yùn)算符的簡(jiǎn)潔性及多用途實(shí)例探究
這篇文章主要為大家介紹了Python中三元運(yùn)算符的簡(jiǎn)潔性及多用途實(shí)例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01Tornado服務(wù)器中綁定域名、虛擬主機(jī)的方法
這篇文章主要介紹了Tornado服務(wù)器中綁定域名、虛擬主機(jī)的方法,本人查看了Tornado才得的方法,特此分享,需要的朋友可以參考下2014-08-08Python實(shí)現(xiàn)批量更換指定目錄下文件擴(kuò)展名的方法
這篇文章主要介紹了Python實(shí)現(xiàn)批量更換指定目錄下文件擴(kuò)展名的方法,結(jié)合完整實(shí)例分析了Python批量修改文件擴(kuò)展名的技巧,并對(duì)比分析了shell命令及scandir的兼容性代碼,需要的朋友可以參考下2016-09-09Django實(shí)現(xiàn)一對(duì)多表模型的跨表查詢方法
今天小編就為大家分享一篇Django實(shí)現(xiàn)一對(duì)多表模型的跨表查詢方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-12-12