python批量修改交換機(jī)密碼的示例
更新時間:2020年09月22日 16:44:16 作者:kylingx
這篇文章主要介紹了python批量修改交換機(jī)密碼的示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
1.通過pip安裝python第三方模塊paramiko
pip install paramiko
2.創(chuàng)建腳本
##導(dǎo)入paramiko、time、getpass模塊 #!/usr/bin/python import paramiko import time import getpass ##通過raw_input()函數(shù)獲取用戶輸入的SSH用戶名并賦值給username username = raw_input('Username:') ##通過getpass模塊中的getpass()函數(shù)獲取用戶輸入字符串作為密碼賦值給password password = getpass.getpass('Password:') ##通過for i in range(1,5)和ip="192.168.100."+str(i)語句實現(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í)行過程賦值給output對象,通過print output語句回顯內(nèi)容 time.sleep(2) output=command.recv(65535) print output ##退出SSH ssh_client.close()
3.執(zhí)行腳本
python changepassword.py Username:admin #手動輸入SSH用戶名,這里是admin Password: #手動輸入SSH用戶密碼,這里是原先密碼
以上就是python批量修改交換機(jī)密碼的示例的詳細(xì)內(nèi)容,更多關(guān)于python批量修改交換機(jī)密碼的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
關(guān)于PySnooper 永遠(yuǎn)不要使用print進(jìn)行調(diào)試的問題
這篇文章主要介紹了關(guān)于PySnooper 永遠(yuǎn)不要使用print進(jìn)行調(diào)試的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03解決Python報錯:ValueError:operands?could?not?be?broadcast?t
這篇文章主要給大家介紹了關(guān)于解決Python報錯:ValueError:operands?could?not?be?broadcast?together?with?shapes的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02Python函數(shù)參數(shù)分類使用與新特性詳細(xì)分析講解
在聲明函數(shù)的時候,一般會根據(jù)函數(shù)所要實現(xiàn)的功能來決定函數(shù)是否需要參數(shù)。在多數(shù)情況下,我們聲明的函數(shù)都會使用到參數(shù),這篇文章主要介紹了Python函數(shù)參數(shù)2023-01-01