网络系统建设与运维(中级) 11.0-Jan16公司网络自动化运维配置v1.3_第1页
网络系统建设与运维(中级) 11.0-Jan16公司网络自动化运维配置v1.3_第2页
网络系统建设与运维(中级) 11.0-Jan16公司网络自动化运维配置v1.3_第3页
网络系统建设与运维(中级) 11.0-Jan16公司网络自动化运维配置v1.3_第4页
网络系统建设与运维(中级) 11.0-Jan16公司网络自动化运维配置v1.3_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

[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网管计算机联网状态下安装模块Python3和paramiko[root@manage~]#yuminstall-ypython3[root@manage~]#pip3installparamiko[root@manage~]#vichangepassword.py##导入paramiko、time、getpass模块#!/usr/bin/pythonimportparamikoimporttimeimportgetpass##通过raw_input()函数获取用户输入的SSH用户名并赋值给usernameusername=raw_input('Username:')##通过getpass模块中的getpass()函数获取用户输入字符串作为密码赋值给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()##调度交换机命令行执行命令command.send("system-view"+"\n")command.send("user-interfaceconsole0"+"\n")command.send("setauthenticationpasswordcipher234567"+"\n")##更改登录密码结束后,返回用户视图并保存配置command.send("return"+"\n")command.send("save"+"\n")command.send("Y"+"\n")command.send("\n")##暂停2秒,并将命令执行过程赋值给output对象,通过printoutput语句回显内容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,结合ip="192.168.100."+str(i)语句循环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"##设置回显内容不分屏显示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"##将查询运行配置的回显内容赋值给recv这个对象recv=command.recv(65535)##将回显内容写入backup这个对象,相当于写入了备份文件中backup.write(recv)##关闭打开的文件backup.close()##结束,断开SSH连接ssh_client.close()[root@manage~]#vi/etc/crontab##在文件末尾填入下列内容后退出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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论