python批量修改交換機(jī)密碼的示例
1.通過(guò)pip安裝python第三方模塊paramiko
pip install paramiko
2.創(chuàng)建腳本
##導(dǎo)入paramiko、time、getpass模塊 #!/usr/bin/python import paramiko import time import getpass ##通過(guò)raw_input()函數(shù)獲取用戶輸入的SSH用戶名并賦值給username username = raw_input('Username:') ##通過(guò)getpass模塊中的getpass()函數(shù)獲取用戶輸入字符串作為密碼賦值給password password = getpass.getpass('Password:') ##通過(guò)for i in range(1,5)和ip="192.168.100."+str(i)語(yǔ)句實(shí)現(xiàn)循環(huán)登錄交換機(jī)SW1-SW4:100.1-4 for i in range(1,5): ip="192.168.100."+str(i) ssh_client=paramiko.SSHClient() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip,username=username,password=password) command=ssh_client.invoke_shell() ##調(diào)度交換機(jī)命令行執(zhí)行命令 command.send("system-view" +"\n") command.send("aaa"+"\n") command.send("local-user admin password cipher Jan16@Hw"+"\n") ##更改登錄密碼結(jié)束后,返回用戶視圖并保存配置 command.send("return"+"\n") command.send("save"+"\n") command.send("Y"+"\n") command.send("\n") ##暫停2秒,并將命令執(zhí)行過(guò)程賦值給output對(duì)象,通過(guò)print output語(yǔ)句回顯內(nèi)容 time.sleep(2) output=command.recv(65535) print output ##退出SSH ssh_client.close()
3.執(zhí)行腳本
python changepassword.py Username:admin #手動(dòng)輸入SSH用戶名,這里是admin Password: #手動(dòng)輸入SSH用戶密碼,這里是原先密碼
以上就是python批量修改交換機(jī)密碼的示例的詳細(xì)內(nèi)容,更多關(guān)于python批量修改交換機(jī)密碼的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python求解任意閉區(qū)間的所有素?cái)?shù)
本篇文章是一篇關(guān)于python求素?cái)?shù)的知識(shí)點(diǎn)內(nèi)容,如果大家在應(yīng)用中有用的到,不妨跟著學(xué)習(xí)下。2018-06-06關(guān)于PySnooper 永遠(yuǎn)不要使用print進(jìn)行調(diào)試的問(wèn)題
這篇文章主要介紹了關(guān)于PySnooper 永遠(yuǎn)不要使用print進(jìn)行調(diào)試的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03解決Python報(bào)錯(cuò):ValueError:operands?could?not?be?broadcast?t
這篇文章主要給大家介紹了關(guān)于解決Python報(bào)錯(cuò):ValueError:operands?could?not?be?broadcast?together?with?shapes的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02Python函數(shù)參數(shù)分類使用與新特性詳細(xì)分析講解
在聲明函數(shù)的時(shí)候,一般會(huì)根據(jù)函數(shù)所要實(shí)現(xiàn)的功能來(lái)決定函數(shù)是否需要參數(shù)。在多數(shù)情況下,我們聲明的函數(shù)都會(huì)使用到參數(shù),這篇文章主要介紹了Python函數(shù)參數(shù)2023-01-01python游戲開(kāi)發(fā)的五個(gè)案例分享
本文給大家分享了作者整理的五個(gè)python游戲開(kāi)發(fā)的案例,通過(guò)具體設(shè)計(jì)思路,代碼等方面詳細(xì)了解python游戲開(kāi)發(fā)的過(guò)程,非常的詳細(xì),希望大家能夠喜歡2020-03-03python自動(dòng)化UI工具發(fā)送QQ消息的實(shí)例
今天小編就為大家分享一篇python自動(dòng)化UI工具發(fā)送QQ消息的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08