吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2917|回复: 31
收起左侧

[Python 原创] 网络设备巡检,可在SecureCRT内执行的Python脚本

  [复制链接]
IceFireKen2727 发表于 2024-1-7 22:31
本帖最后由 IceFireKen2727 于 2024-2-22 15:15 编辑

简介

  • 工作中经常需要对客户的网络设备进行巡检,如果工程师PC可以接入到客户的网络中去使用远程登录的方式巡检(如SSH),那么使用Devices_Inspection脚本就可以完成巡检操作;52pojie帖子

  • 但是偶尔也会遇到直接从Console口登录设备进行巡检的情况,就需要从SecureCRT软件依次输入多个命令收集巡检信息的操作;

  • 本脚本可以在SecureCRT中运行,利用脚本代替手动输入巡检命令的过程。

使用方法

  1. 在SecureCRT的Session Options —— Terminal —— Mapped Keys, 映射快捷键(如F1),Function选择Run Script,选择本脚本。

  2. 之后,按F1执行脚本会弹出如下提示:

    13-14-46

    按提示输入正确的【设备类型】就可以开始巡检了。

注意事项:

  • 本脚本只是代替人工手动输入巡检命令的过程,并不涉及登录。

  • 巡检时记得开启记录Log Session记录回显内容。

  • 执行脚本前CLI预先进入设备全局模式,保证巡检命令能够被正确执行。

目前支持的设备类型

  • cisco
  • huawei
  • h3c
  • asa
  • nxos
  • a10
  • ruijie
# $language = "Python"
# $interface = "1.0"

cisco_cmds_list = ['terminal length 0',
                   'show clock detail',
                   'show inventory',
                   'show env all',
                   'show module all',
                   'show environment',
                   'show power',
                   'show redundancy',
                   'show redundancy switchover history',
                   'dir',
                   'show boot',
                   'show processes cpu',
                   'show processes memory',
                   'show license udi',
                   'show license all',
                   'show license feature',
                   'show logging',
                   'show version',
                   'show vtp status',
                   'show vtp password',
                   'show vlan brief',
                   'show ip interface brief',
                   'show interfaces status',
                   'show cdp neighbors',
                   'show ip route',
                   'show ip ospf neighbor',
                   'show ip ospf interface brief',
                   'show ip eigrp neighbors',
                   'show ip eigrp interfaces',
                   'verify /md5 system:running-config',
                   'show running-config',
                   'terminal length 24']

huawei_cmds_list = ['screen-length 0 temporary',
                    'display clock',
                    'display esn',
                    'display environment',
                    'display power',
                    'dir flash:',
                    'display cpu',
                    'display cpu history',
                    'display memory',
                    'display license',
                    'display log',
                    'display version',
                    'display vlan',
                    'display interface brief',
                    'display ip interface brief',
                    'display lldp neighbor brief',
                    'display ip routing-table',
                    'display ospf peer',
                    'display ospf interface',
                    'display current-configuration',
                    'screen-length 24 temporary']

h3c_cmds_list = ['screen-length disable',
                 'display clock',
                 'display device manuinfo',
                 'display fan',
                 'display transceiver disgnosis interface',
                 'display environment',
                 'display power',
                 'display boot-loader',
                 'display cpu',
                 'display cpu history',
                 'display memory summary',
                 'display license',
                 'display license feature',
                 'display log',
                 'display version',
                 'display vlan brief',
                 'display interface brief',
                 'display ip interface brief',
                 'display lldp neighbor-information list',
                 'display ip routing-table',
                 'display ospf peer',
                 'display ospf interface',
                 'display current-configuration',
                 'undo screen-length disable']

ciscoasa_cmds_list = ['terminal pager 0',
                      'show inventory',
                      'dir',
                      'show bootvar',
                      'show cpu usage detailed',
                      'show memory',
                      'show license udi',
                      'show license all',
                      'show license feature',
                      'show logging',
                      'show version',
                      'show failover state',
                      'show failover',
                      'show vlan',
                      'show interface ip brief',
                      'show interfaces status',
                      'show route',
                      'show ospf neighbor',
                      'show ospf interface brief',
                      'show eigrp neighbors',
                      'show eigrp interfaces',
                      'verify /md5 system:running-config',
                      'show running-config',
                      'terminal pager 24']

nxos_cmds_list = ['terminal length 0',
                  'show clock detail',
                  'show inventory',
                  'show module',
                  'show environment',
                  'show vdc',
                  'show redundancy status',
                  'show vpc',
                  'dir',
                  'show boot',
                  'show processes cpu',
                  'show processes memory',
                  'show license',
                  'show license host-id',
                  'show license usage',
                  'show logging',
                  'show version',
                  'show vtp status',
                  'show vtp password',
                  'show vlan brief',
                  'show fex',
                  'show ip interface brief',
                  'show interface brief',
                  'show interfaces status',
                  'show cdp neighbors',
                  'show ip route',
                  'show ip ospf neighbor',
                  'show ip ospf interface brief',
                  'show ip eigrp neighbors',
                  'show ip eigrp interfaces',
                  'show running-config',
                  'terminal length 24']

a10_cmds_list = ['terminal length 0',
                 'show clock',
                 'show version',
                 'show cpu',
                 'show memory',
                 'show disk',
                 'show log',
                 'show ip interfaces',
                 'show interfaces brief',
                 'show vrrp-a',
                 'show ip route',
                 'show gslb group brief',
                 'show running-config',
                 'terminal length 24']

ruijie_cmds_list = ['terminal length 0',
                   'show clock',
                   'show cpu',
                   'show memory',
                   'show license all-license',
                   'show logging',
                   'show version',
                   'show vlan',
                   'show ip interface brief',
                   'show interfaces status',
                   'show ip route',
                   'show ip ospf neighbor',
                   'show ip ospf interface brief',
                   'show running-config',
                   'terminal length 24']

end_cmd = '\n'

sleep_time = 2

supported_device_type = ['cisco', 'huawei', 'h3c', 'asa', 'nxos', 'a10', 'ruijie']

device_type = crt.Dialog.Prompt('请输入支持的设备类型:\n  cisco、huawei、h3c、asa、nxos、a10、ruijie', '请确认设备类型')

if device_type not in supported_device_type:
    crt.Dialog.MessageBox('尚不支持的设备类型。', '设备类型错误', 48)

crt.Screen.Synchronous = True

def main():
    crt.Screen.Send(end_cmd * 3)
    if device_type == 'cisco':
        for cmd in cisco_cmds_list:
            crt.Screen.Send(cmd + end_cmd * 4)
            crt.Sleep(sleep_time)
    elif device_type == 'huawei':
        for cmd in huawei_cmds_list:
            crt.Screen.Send(cmd + end_cmd * 4)
            crt.Sleep(sleep_time)
    elif device_type == 'h3c':
        for cmd in h3c_cmds_list:
            crt.Screen.Send(cmd + end_cmd * 4)
            crt.Sleep(sleep_time)
    elif device_type == 'asa':
        for cmd in ciscoasa_cmds_list:
            crt.Screen.Send(cmd + end_cmd * 4)
            crt.Sleep(sleep_time)
    elif device_type == 'nxos':
        for cmd in nxos_cmds_list:
            crt.Screen.Send(cmd + end_cmd * 4)
            crt.Sleep(sleep_time)
    elif device_type == 'a10':
        for cmd in a10_cmds_list:
            crt.Screen.Send(cmd + end_cmd * 4)
            crt.Sleep(sleep_time)
    elif device_type == 'ruijie':
        for cmd in ruijie_cmds_list:
            crt.Screen.Send(cmd + end_cmd * 4)
            crt.Sleep(sleep_time)

main()

GitHub

项目链接

  • Bug反馈可以用GitHub账户上的邮箱联系,来信请注明【网络设备巡检脚本】

inspection_script.zip

1.5 KB, 下载次数: 109, 下载积分: 吾爱币 -1 CB

免费评分

参与人数 8吾爱币 +10 热心值 +7 收起 理由
anning666 + 1 + 1 谢谢@Thanks!
smile1110 + 2 + 1 热心回复!
sbwfnhn + 1 东西很不错,不过已有snmp、C/S架构的监控平台替代。
Urmimi + 1 谢谢@Thanks!
jack_cc + 1 + 1 热心回复!
qiangX023 + 1 热心回复!
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
chenzanlin + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| IceFireKen2727 发表于 2024-3-15 23:29
jungege888 发表于 2024-3-15 14:51
Could not locate script engine for language Python  ,error:0x800401f3           这个什么情况

没有安装ActivePython,可以根据自己的版本安装ActivePython。
这是从网上查到的信息,可能是CRT安装时带的一个组件,你的CRT是免安装的版本吗?
换安装版试试。
jungege888 发表于 2024-3-15 14:51
Could not locate script engine for language Python  ,error:0x800401f3           这个什么情况
chenzanlin 发表于 2024-1-7 23:13
xiaoaivcm 发表于 2024-1-8 00:19
感谢分享
li000yu 发表于 2024-1-8 00:44
感谢感谢,同为网工
weipohai 发表于 2024-1-8 07:35
感谢分享,设备多了就想着用脚本
baoqingzxc 发表于 2024-1-8 07:39
感谢大佬分享,这个思路不错!受教了!
simoney 发表于 2024-1-8 08:17

感谢大佬分享
Song0913 发表于 2024-1-8 08:26
有没有结果输出?
Peter9860511 发表于 2024-1-8 09:01
这个得留下来
小哲网络 发表于 2024-1-8 09:14
感谢分享!!!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 04:18

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表