python利用paramiko實(shí)現(xiàn)交換機(jī)巡檢的示例
直接上代碼
#-*- coding:UTF-8 -*-import paramikoimport timestarttime = time.strftime(’%Y-%m-%d %T’)start_info = '巡檢開始時(shí)間:'+str(starttime)cmd_filepath = r'd:Pythonpyxunjiancmd.txt'cmd_file = open(cmd_filepath,'r')cmds = cmd_file.readlines()dev_filepath = r'd:Pythonpyxunjiandevice_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(’Nn’) #該行非必須 command.send(’screen-length 0 temporaryn’) #取消分屏顯示 for cmd in cmds: command.send(cmd+’n’) time.sleep(5) output = command.recv(65535).decode() log = open(r'd:Pythonpyxunjian'+ip+'.txt',’a’) endtime = time.strftime(’%Y-%m-%d %T’) end_info = '巡檢結(jié)束時(shí)間:'+str(endtime) log.write(start_info+’nn’+output+’nn’+end_info) log.close()dev_file.close()#巡檢命令文檔cmd.txtdisplay devicedisplay environmentdisplay alarm urgendisplay memory-usagedisplay cpu-usagedisplay logbuffer level 0display logbuffer level 1display logbuffer level 2display logbuffer level 3display logbuffer level 4#設(shè)備信息 device_info.txt192.168.10.11,admin,Huawei@123192.168.10.12,admin,Huawei@123192.168.10.13,admin,Huawei@123192.168.10.14,admin,Huawei@123
以上就是python利用paramiko實(shí)現(xiàn)交換機(jī)巡檢的示例的詳細(xì)內(nèi)容,更多關(guān)于paramiko交換機(jī)巡檢的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. Docker 啟動(dòng)Redis 并設(shè)置密碼的操作2. asp文件用什么軟件編輯3. ASP新手必備的基礎(chǔ)知識(shí)4. CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )5. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對(duì)象6. python 實(shí)現(xiàn)有道翻譯功能7. JAVA 實(shí)現(xiàn)延遲隊(duì)列的方法8. vue限制輸入數(shù)字或者保留兩位小數(shù)實(shí)現(xiàn)9. vue+element開發(fā)一個(gè)谷歌插件的全過程10. 利用CSS制作3D動(dòng)畫

網(wǎng)公網(wǎng)安備