因安全规则要求,必须定期修改交换机密码, 而交换机数量多,所以配置了一个脚本远程自动修改。
脚本命令如下:
# $language = "VBScript"
# $interface = "1.0"
' Connect to an SSH server using the SSH2 protocol. Specify the
' username and password and hostname on the command line as well as
' some SSH2 protocol specific options.
Sub Main
Dim user
user = "***" 'ssh登录设备时的用户名
Dim passwd
passwd = "*******" ’ssh登录的密码
Dim superpwd
superpwd="******" '原来super3的密码
Dim fso,file,host
'打开保存设备管理地址文件
Const ForReading = 1,ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
'定义一个ip列表文档,将所有交换机的ip地址单独列出,表格无需任何格式,只用每行一个ip地址就可以
Set file = fso.OpenTextFile("D:\办公文档\运维管理\修改交换机super3密码\ip.txt",Forreading, False)
crt.Screen.Synchronous = True
DO While file.AtEndOfStream <> True
'读出每行,将每一行ip赋予host
host = file.ReadLine
crt.session.LogFileName = "D:\办公文档\运维管理\修改交换机super3密码\" & host & ".txt"
crt.session.Log(true)
' SSH登陆
cmd = "/SSH2 /L " & user & " /PASSWORD " & passwd & " /C AES-128 /M MD5 " & host
crt.Session.Connect cmd
'输入super 密码
crt.Screen.WaitForString ">"
crt.Screen.Send "super" & Chr(13)
crt.Screen.WaitForString ":"
crt.Screen.Send superpwd & Chr(13)
'登录系统视图
crt.Screen.WaitForString ">"
crt.Screen.Send "sys" & Chr(13)
crt.Screen.WaitForString "]"
'修改super3密码
crt.Screen.Send "super password level 3 cipher 123456"& Chr(13) '123456为你修改的密码
crt.Screen.WaitForString "]"
'保存配置
crt.Screen.Send "save"& Chr(13)
crt.Screen.Send "Y" & Chr(13)
crt.Screen.WaitForString ":"
crt.Screen.Send ""& Chr(13)
crt.Screen.WaitForString "[Y/N]:"
crt.Screen.Send "Y" & Chr(13)
crt.Screen.WaitForString "successfully."
crt.Screen.Send ""& Chr(13)
crt.Screen.WaitForString "]"
'退出程序
crt.Screen.Send "quit"& Chr(13)
crt.Screen.WaitForString ">"
crt.Screen.Send "quit"& Chr(13)
crt.Session.Disconnect
loop
crt.Screen.Synchronous = False
End Sub
本文出自 “hongbifu” 博客,请务必保留此出处http://flambee.blog.51cto.com/112166/1593553