網(wǎng)絡系統(tǒng)建設與運維(中級) 11.0-Jan16公司網(wǎng)絡自動化運維配置v1.3_第1頁
網(wǎng)絡系統(tǒng)建設與運維(中級) 11.0-Jan16公司網(wǎng)絡自動化運維配置v1.3_第2頁
網(wǎng)絡系統(tǒng)建設與運維(中級) 11.0-Jan16公司網(wǎng)絡自動化運維配置v1.3_第3頁
網(wǎng)絡系統(tǒng)建設與運維(中級) 11.0-Jan16公司網(wǎng)絡自動化運維配置v1.3_第4頁
網(wǎng)絡系統(tǒng)建設與運維(中級) 11.0-Jan16公司網(wǎng)絡自動化運維配置v1.3_第5頁
已閱讀5頁,還剩16頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

[Huawei]system-view[Huawei]sysnameR1[R1]interfaceGigabitEthernet0/0/0[R1-GigabitEthernet0/0/0]ipaddress192.168.1.10255.255.255.0[R1]interfaceGigabitEthernet0/0/1[R1-GigabitEthernet0/0/1]ipaddress20.20.20.1255.255.255.0[R1]interfaceGigabitEthernet0/0/2[R1-GigabitEthernet0/0/2]ipaddress30.30.30.1255.255.255.0[Huawei]system-view[Huawei]sysnameR2[R2]interfaceGigabitEthernet0/0/0[R2-GigabitEthernet0/0/0]ipaddress172.16.1.10255.255.255.0[R2]interfaceGigabitEthernet0/0/1[R2-GigabitEthernet0/0/1]ipaddress20.20.20.10255.255.255.0[R2]interfaceGigabitEthernet0/0/2[R2-GigabitEthernet0/0/2]ipaddress40.40.40.10255.255.255.0[Huawei]system-view[Huawei]sysnameR3[R3]interfaceGigabitEthernet0/0/0[R3-GigabitEthernet0/0/0]ipaddress10.10.10.10255.255.255.0[R3]interfaceGigabitEthernet0/0/1[R3-GigabitEthernet0/0/1]ipaddress40.40.40.1255.255.255.0[R3]interfaceGigabitEthernet0/0/2[R3-GigabitEthernet0/0/2]ipaddress30.30.30.10255.255.255.0[R1]ospf1[R1-ospf-1]area0[R1-ospf-1-area-0.0.0.0]network192.168.1.00.0.0.255[R1-ospf-1-area-0.0.0.0]network20.20.20.00.0.0.255[R1-ospf-1-area-0.0.0.0]network30.30.30.00.0.0.255[R2]ospf1[R2-ospf-1]area0[R2-ospf-1-area-0.0.0.0]network172.16.1.00.0.0.255[R2-ospf-1-area-0.0.0.0]network20.20.20.00.0.0.255[R2-ospf-1-area-0.0.0.0]network40.40.40.00.0.0.255[R3]ospf1[R3-ospf-1]area0[R3-ospf-1-area-0.0.0.0]network10.10.10.00.0.0.255[R3-ospf-1-area-0.0.0.0]network40.40.40.00.0.0.255[R3-ospf-1-area-0.0.0.0]network30.30.30.00.0.0.255[R1]rsalocal-key-paircreateThekeynamewillbe:Host%RSAkeysdefinedforHostalreadyexist.Confirmtoreplacethem?(y/n)[n]:yTherangeofpublickeysizeis(512~2048).NOTES:Ifthekeymodulusisgreaterthan512,Itwilltakeafewminutes.Inputthebitsinthemodulus[default=512]:2048[R1-aaa]local-useradminpasswordcipher123456[R1-aaa]local-useradminprivilegelevel3[R1-aaa]local-useradminservice-typessh[R1-aaa]stelnetserverenableInfo:SucceededinstartingtheSTELNETserver.[R1]sshuseradminauthentication-typepasswordAuthenticationtypesetted,andwillbeineffectnexttime[R1]user-interfacevty04[R1-ui-vty0-4]authentication-modeaaa[R1-ui-vty0-4]protocolinboundssh[R2]rsalocal-key-paircreateThekeynamewillbe:Host%RSAkeysdefinedforHostalreadyexist.Confirmtoreplacethem?(y/n)[n]:yTherangeofpublickeysizeis(512~2048).NOTES:Ifthekeymodulusisgreaterthan512,Itwilltakeafewminutes.Inputthebitsinthemodulus[default=512]:2048[R2-aaa]local-useradminpasswordcipher123456[R2-aaa]local-useradminprivilegelevel3[R2-aaa]local-useradminservice-typessh[R2-aaa]stelnetserverenableInfo:SucceededinstartingtheSTELNETserver.[R2]sshuseradminauthentication-typepasswordAuthenticationtypesetted,andwillbeineffectnexttime[R2]user-interfacevty04[R2-ui-vty0-4]authentication-modeaaa[R2-ui-vty0-4]protocolinboundssh[R3]rsalocal-key-paircreateThekeynamewillbe:Host%RSAkeysdefinedforHostalreadyexist.Confirmtoreplacethem?(y/n)[n]:yTherangeofpublickeysizeis(512~2048).NOTES:Ifthekeymodulusisgreaterthan512,Itwilltakeafewminutes.Inputthebitsinthemodulus[default=512]:2048[R3-aaa]local-useradminpasswordcipher123456[R3-aaa]local-useradminprivilegelevel3[R3-aaa]local-useradminservice-typessh[R3-aaa]stelnetserverenableInfo:SucceededinstartingtheSTELNETserver.[R3]sshuseradminauthentication-typepasswordAuthenticationtypesetted,andwillbeineffectnexttime[R3]user-interfacevty04[R3-ui-vty0-4]authentication-modeaaa[R3-ui-vty0-4]protocolinboundssh網(wǎng)管計算機聯(lián)網(wǎng)狀態(tài)下安裝模塊Python3和paramiko[root@manage~]#yuminstall-ypython3[root@manage~]#pip3installparamiko[root@manage~]#vichangepassword.py##導入paramiko、time、getpass模塊#!/usr/bin/pythonimportparamikoimporttimeimportgetpass##通過raw_input()函數(shù)獲取用戶輸入的SSH用戶名并賦值給usernameusername=raw_input('Username:')##通過getpass模塊中的getpass()函數(shù)獲取用戶輸入字符串作為密碼賦值給passwordpassword=getpass.getpass('Password:')foriin["192.168.1.2","172.16.1.2","10.10.10.2"]:ip=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)度交換機命令行執(zhí)行命令command.send("system-view"+"\n")command.send("user-interfaceconsole0"+"\n")command.send("setauthenticationpasswordcipher234567"+"\n")##更改登錄密碼結(jié)束后,返回用戶視圖并保存配置command.send("return"+"\n")command.send("save"+"\n")command.send("Y"+"\n")command.send("\n")##暫停2秒,并將命令執(zhí)行過程賦值給output對象,通過printoutput語句回顯內(nèi)容time.sleep(2)output=command.recv(65535)printoutput##退出SSHssh_client.close()[root@manage~]#vibackup.py##導入paramiko、time、datetime等模塊#!/usr/bin/pythonimportparamikoimporttimefromdatetimeimportdatetime##設置SSH用戶名和密碼username="admin"password="234567"##通過for語句遍歷i的值為1/2/3/4,結(jié)合ip="192.168.100."+str(i)語句循環(huán)SSH登錄交換機設備foriinrange(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()##提示SSH登錄成功print"ssh"+ip+"successfully"##設置回顯內(nèi)容不分屏顯示command.send("screen-length0temporary"+"\n")##獲取交換機運行配置output=(command.send("displaycurrent-configuration"+"\n"))##程序暫停2秒time.sleep(2)##讀取當前時間now=datetime.now()##打開備份文件backup=open("/root/backup/"+str(now.year)+"-"+str(now.month)+"-"+str(now.day)+"-"+ip+".txt","a+")##提示正在備份print"backuping"##將查詢運行配置的回顯內(nèi)容賦值給recv這個對象recv=command.recv(65535)##將回顯內(nèi)容寫入backup這個對象,相當于寫入了備份文件中backup.write(recv)##關閉打開的文件backup.close()##結(jié)束,斷開SSH連接ssh_client.close()[root@manage~]#vi/etc/crontab##在文件末尾填入下列內(nèi)容后退出001***rootpython/root/backup.py[root@manage~]#mkdir/root/backup[root@manage~]#systemctlrestartcrond[root@manage~]#systemctlenablecrond[root@manage~]#./changepassword.pyUsername:adminPassword:Userlastlogininformation:AccessType:SSHIP-Address:192.168.1.130sshTime:2020-02-2910:31:35-08:00<R1>system-viewEntersystemview,returnuserviewwithCtrl+Z.[R1]user-interfaceconsole0[R1-ui-console0]setauthenticationpasswordcipher234567[R1-ui-console0]return<R1>saveThecurrentconfigurationwillbewrittentothedevice.Areyousuretocontinue?(y/n)[n]:YItwilltakeseveralminutestosaveconfigurationfile,pleasewait...Userlastlogininformation:AccessType:SSHIP-Address:192.168.1.130sshTime:2020-02-2910:31:38-08:00<R2>system-viewEntersystemview,returnuserviewwithCtrl+Z.[R2]user-interfaceconsole0[R2-ui-console0]setauthenticationpasswordcipher234567[R2-ui-console0]return<R2>saveThecurrentconfigurationwillbewrittentothedevice.Areyousuretocontinue?(y/n)[n]:YItwilltakeseveralminutestosaveconfigurationfile,pleasewait...Userlastlogininformation:AccessType:SSHIP-Address:192.168.1.130sshTime:2020-02-2910:31:41-08:00<R3>system-viewEntersystemview,returnuserviewwithCtrl+Z.[R3]user-interfaceconsole0[R3-ui-console0]setauthenticationpasswordcipher234567[R3-ui-console0]return<R3>saveThecurrentconfigurationwillbewrittentothedevice.Areyousuretocontinue?(y/n)[n]:YItwilltakeseveralminutestosaveconfigurationfile,pleasewait...[root@manage~]#cd/root/backup[root@managebackup]#ls2020-2-28-10.10.10.2.txt2020-2-28-172.16.1.2.txt2020-2-28-192.168.1.2.txt[root@managebackup]#ll-rw-r--r--.1rootroot1786Feb281:002020-2-28-10.10.10.2.txt-rw-r--r--.1rootroot1809Feb281:002020-2-28-172.16.1.2.txt-rw-r--r--.1rootroot1762Feb281:002020-2-28-192.168.1.2.txt[root@managebackup]#cat2020-2-28-10.10.10.2.txtUserlastlogininformation:AccessType:SSHIP-Address:192.168.1.130sshTime:2020-02-2910:32:24-08:00<R3>screen-length0temporaryInfo:Theconfigurationtakeseffectonthecurrentuserterminalinterfaceonly.<R3>displaycurrent-configuration[V200R003C00]#sysnameR3#snmp-agentlocal-engineid800007DB03000000000000snmp-agent#clocktimezoneChina-Standard-Timeminus08:00:00#portallocal-serverloadflash:/portalpage.zip#dropillegal-macalarm#wlanac-globalcarrieridotheracid0#setcpu-usaget

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論