6、示例脚本:SNMP读取网络设备接口数据ifDescr,ifInOctets,ifOutOctets[C:\snmlipv6\snmp\snmp_ipv4_interfaces.txt]

本地打包下载:https://files.cnblogs.com/files/snmlsnmpsshtelnetipv6/snml_utf8ipv6.zip

6、示例脚本:读取网络设备接口数据[C:\snmlipv6\snmp\snmp_ipv4_interfaces.txt]

  C:\snmlipv6\snmp\snmp_ipv4_interfaces.txt
001 run.set logevel {nolog}
002 screen.set color red {0} green {0} blue {0}
003 screen.text at point {150} {10} string {10.snmp (ipv4): mib-2.interfaces }
004  
005 snmp.open version {2c} ip {192.168.186.132} port {161} password {cisco}
006 screen.set color red {0} green {0} blue {255}
007 snmp.get var {system.sysDescr} oid {1.3.6.1.2.1.1.1.0}
008 screen.text at point {5} {30} string {snmp.get (oid:1.3.6.1.2.1.1.1.0 -- system.sysDescr) return value:}
009 screen.set color red {0} green {0} blue {0}
010 screen.text at point {5} {48} string {[~system.sysDescr~]}
011 snmp.get var {interfaces.ifNumber} oid {1.3.6.1.2.1.2.1.0}
012 screen.set color red {0} green {0} blue {255}
013 screen.text at point {5} {110} string {snmp.get (oid:1.3.6.1.2.1.2.1.0 -- interfaces.ifNumber) return value: [~interfaces.ifNumber~]}
014  
015 screen.set color red {0} green {0} blue {0}
016 var {v_y} value {140}
017 screen.text at point {8} {~v_y~} string {ifIndex}
018 screen.line from point {10} {155} to point {40} {155}
019 screen.text at point {60} {~v_y~} string {ifDescr:1.3.6.1.2.1.2.2.1.2.X}
020 screen.line from point {50} {155} to point {230} {155}
021 screen.text at point {270} {~v_y~} string {ifInOctets}
022 screen.line from point {250} {155} to point {350} {155}
023 screen.text at point {390} {~v_y~} string {ifOutOctets}
024 screen.line from point {370} {155} to point {470} {155}
025  
026 var {v_time} value datetime
027 var {v_i} value {0}
028  
029 loop.begin
030   
031   var {v_i} add number {1}
032   var {v_y} add number {18}
033   
034   screen.text at point {10} {~v_y~} string {~v_i~}
035   
036   snmp.get var {ifDescr.~v_i~} oid {1.3.6.1.2.1.2.2.1.2.~v_i~}
037   var {snmp.value} copy var {ifDescr.~v_i~}
038   screen.text at point {50} {~v_y~} string {~snmp.value~}
039   
040   snmp.get var {ifInOctets.~v_i~} oid {1.3.6.1.2.1.2.2.1.10.~v_i~}
041   var {snmp.value} copy var {ifInOctets.~v_i~}
042   screen.text at point {250} {~v_y~} string {~snmp.value~}
043   
044   snmp.get var {ifOutOctets.~v_i~} oid {1.3.6.1.2.1.2.2.1.16.~v_i~}
045   var {snmp.value} copy var {ifOutOctets.~v_i~}
046   screen.text at point {370} {~v_y~} string {~snmp.value~}
047   
048   if.var {v_i} > {~interfaces.ifNumber~}
049     loop.exit
050   if.end
051 loop.end
052 run.end

脚本执行结果如下:

6、示例脚本:SNMP读取网络设备接口数据ifDescr,ifInOctets,ifOutOctets[C:\snmlipv6\snmp\snmp_ipv4_interfaces.txt]
6、示例脚本:SNMP读取网络设备接口数据ifDescr,ifInOctets,ifOutOctets[C:\snmlipv6\snmp\snmp_ipv4_interfaces.txt]
脚本执行后变量值如下:

  31 snmp.MajorVersion=[2]
  32 snmp.MinorVersion=[0]
  33 snmp.Level=[2]
  34 snmp.TranslateMode=[1]
  35 snmp.RetransmitMode=[1]
  36 system.sysDescr=[Cisco IOS Software, 7200 Software (C7200-ADVENTERPRISEK9-M), Version 15.2(4)M10, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Mon 07-Mar-16 06:52 by prod_rel_team]
  37 interfaces.ifNumber=[8]
  38 v_y=[302]
  39 v_time=[2020-02-29 23:24:49]
  40 v_i=[9]
  41 ifDescr.1=[FastEthernet0/0]
  42 snmp.value=[NULL]
  43 ifInOctets.1=[42148071]
  44 ifOutOctets.1=[42185580]
  45 ifDescr.2=[FastEthernet1/0]
  46 ifInOctets.2=[0]
  47 ifOutOctets.2=[157693]
  48 ifDescr.3=[Ethernet2/0]
  49 ifInOctets.3=[0]
  50 ifOutOctets.3=[0]
  51 ifDescr.4=[Ethernet2/1]
  52 ifInOctets.4=[0]
  53 ifOutOctets.4=[0]
  54 ifDescr.5=[Ethernet2/2]
  55 ifInOctets.5=[0]
  56 ifOutOctets.5=[0]
  57 ifDescr.6=[Ethernet2/3]
  58 ifInOctets.6=[0]
  59 ifOutOctets.6=[0]
  60 ifDescr.7=[VoIP-Null0]
  61 ifInOctets.7=[0]
  62 ifOutOctets.7=[0]
  63 ifDescr.8=[Null0]
  64 ifInOctets.8=[0]
  65 ifOutOctets.8=[0]
  66 ifDescr.9=[NULL]
  67 ifInOctets.9=[NULL]
  68 ifOutOctets.9=[NULL]
  69 run.end=[run.end]

目录: 1、var 2、screen 3、snmp 4、telnet 5、text 6、if 7、loop 8、dns 9、ping 10、arp 11、excel 12、smtp 13、tcp 14、udp 15、ssh 16、web 17、mysql 18、sqlite 19、Run 20、sys 21、macro 附录1、全部语句

上一篇:snmp中载入第三方mib库(转载)


下一篇:[技术干货] 博科光交机SNMP配置