python批量修改交換機(jī)密碼的示例
1.通過(guò)pip安裝python第三方模塊paramiko
pip install paramiko
2.創(chuàng)建腳本
##導(dǎo)入paramiko、time、getpass模塊#!/usr/bin/pythonimport paramikoimport timeimport getpass##通過(guò)raw_input()函數(shù)獲取用戶輸入的SSH用戶名并賦值給usernameusername = raw_input(’Username:’)##通過(guò)getpass模塊中的getpass()函數(shù)獲取用戶輸入字符串作為密碼賦值給passwordpassword = 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-4for 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##退出SSHssh_client.close()
3.執(zhí)行腳本
python changepassword.py Username:admin #手動(dòng)輸入SSH用戶名,這里是adminPassword: #手動(dòng)輸入SSH用戶密碼,這里是原先密碼
以上就是python批量修改交換機(jī)密碼的示例的詳細(xì)內(nèi)容,更多關(guān)于python批量修改交換機(jī)密碼的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. html中的form不提交(排除)某些input 原創(chuàng)2. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享3. ASP常用日期格式化函數(shù) FormatDate()4. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫(huà)特效5. asp.net core項(xiàng)目授權(quán)流程詳解6. XMLHTTP資料7. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式8. CSS3中Transition屬性詳解以及示例分享9. jsp文件下載功能實(shí)現(xiàn)代碼10. 開(kāi)發(fā)效率翻倍的Web API使用技巧
