其他分享
首页 > 其他分享> > 利用CRT配合VBS脚本实现自动化巡检

利用CRT配合VBS脚本实现自动化巡检

作者:互联网

利用CRT配合VBS脚本实现自动化巡检

以山石防火墙巡检为例

目录

1 设备列表文件:list.txt

内容格式:主机名[空格]IP[空格]SSH用户名[空格]SSH密码

SG-6000 192.168.1.1 hillstone Admin@123
SG-6000-02 192.168.1.2 hillstone Admin@123

2 VBS脚本: 2022山石巡检.vbs

#$language = "VBScript"
#$interface = "1.0"

' Hillstone防火墙巡检脚本V1.0
' 注意:
' 请在英文路径下使用,中文路径可能会报错。
' 要求主机名与设备配置一致,不一致结果可能会出错。

crt.Screen.Synchronous = True

Sub Main
    '打开设备列表文件。格式:设备主机名 ip地址 ssh登录账号 ssh密码
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,params
Set fso = CreateObject("Scripting.FileSystemObject")
'定义设备列表文件位置
Set file1 = fso.OpenTextFile("C:\Users\fcarey\Desktop\checkTmp\list.txt",Forreading, False)
crt.Screen.Synchronous = True
DO While file1.AtEndOfStream <> True
	'读出每行
	line = file1.ReadLine
	'分离每行的参数:主机名 IP地址 用户名 密码
	params = Split(line)
	'定义输出日志名称:主机名_IP.txt
	'crt.session.LogFileName = "C:\Users\fcarey\Desktop\checkTmp\logfiles\" & params(0) & "_" & params(1) & ".txt"
	'定义输出日志名称:主机名.txt
	crt.session.LogFileName = "C:\Users\fcarey\Desktop\checkTmp\logfiles\" & params(0) & ".txt"
	crt.session.Log(true)
	'SSH到这个设备上
	crt.Session.Connect ("/SSH2 /PASSWORD "& params(3) & " " & params(2) & "@" & params(1))
	'巡检命令
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "ter len 0" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "ter width 512" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show config" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show version detail" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show version" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show module" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show interface" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show session generic detail" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show session generic" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show memory" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show memory detail" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show cpu " & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show cpu detail" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show ip route static" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show ip route" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show arp" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show environment" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show ha group 0" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show dp-filter" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show dp filter" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show snat resource" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show snat rule" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show snat" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show dnat rule" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show dnat" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show license" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show logging event " & chr(124) & " include 2022" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show logg alarm " & chr(124) & " include 2022" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show logg security " & chr(124) & " include 2022" & chr(13)
	crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "show tech-support toconsole" & chr(13)
    crt.Screen.WaitForString params(0) & "# "
	crt.Screen.Send "ter len 50" & chr(13)
	crt.Screen.WaitForString params(0) & "# " 
	crt.Screen.Send chr(13)
    
	'存在more时的脚本
	'Do Until crt.Screen.WaitForString ("---- More ----",3) = False
	'crt.Screen.Send " "
	'loop

	'备份完成后退出
	crt.Session.Disconnect
loop
crt.Screen.Synchronous = False

End Sub

3 使用方式

打开CRT --> Script --> Run --> 选择"2022山石巡检.vbs" --> 等待输出结果 --> 确认并拷贝结果 --> 跑路。

标签:巡检,CRT,crt,Screen,Send,VBS,chr,params,WaitForString
来源: https://www.cnblogs.com/f-carey/p/16363840.html