利用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" --> 等待输出结果 --> 确认并拷贝结果 --> 跑路。

最新文章

  1. struts2杂记(一)——使用doubleSelect
  2. springboot @ConfigurationProperties
  3. JavaScript鼠标经过图片的放大镜效果
  4. JScrollBar
  5. zTree开发下拉树
  6. dede教程之后台登录是自动跳出解决方法
  7. 1st-code-review summary
  8. nginx静态资源分离部署
  9. 【sqlserver】批量插入10万数据
  10. poj1833---字典序算法
  11. 【UVA】12299-RMQ with Shifts(线段树)
  12. 修改tomcat图标
  13. Vim实现分屏
  14. AD域安装及必要设置
  15. 实用的shell脚本面试题和答案
  16. 史上最简单的 SpringCloud 教程 | 终章
  17. 程序猿必备的10款超有趣的SVG绘制动画赏析
  18. 关于Java大数操作(BigInteger、BigDecimal)
  19. Nginx 日志分析命令
  20. Android—— Fragment 真正的完全解析(上)(转)

热门文章

  1. c++ trivial, standard layout和POD类型解析
  2. Dev-Cpp下载与安装
  3. 【Scala】思维导图
  4. Mybatis-Plus 对 json 的存储使用支持
  5. Nginx rewrite 详解
  6. SpringBoot向Excel模板中写入数据并下载 (无需获取file对象及模板绝对路径)
  7. 如何使用 IdGen 生成 UID
  8. 时间片差分调度法-充分利用MCU的资源
  9. 红袖添香,绝代妖娆,Ruby语言基础入门教程之Ruby3基础数据类型(data types)EP02
  10. python里面一些零碎知识点