TCL/EXPECT自动化测试脚本实例六 --- SNMP community长度测试

    本文通过一个测试SNMP community最大长度的脚本,介绍自动测试SNMP agent的方法。

    下面通过一个测试SNMP community最大长度的脚本,介绍一下net-snmp工具。

    net-snmp是一组基于命令行的snmp manager工具,可以在命令行下进行snmp get, snmp set, snmp walk等操作,支持snmp v1/v2c/v3。原来的名字叫做ucd-snmp,也已经被移植到windows NT上。
它的主页在http://net-snmp.sourceforge.net/

    由于它可以在命令行下进行SNMP操作,所以可以和TCL/expect很好的结合,完成自动化测试的功能。
下面的脚本(snmp.exp),不断的增加SNMP community,长度从1到256,每增加一个community,就调用snmp-get来进行SNMP get操作,如果get成功,说明此community有效;反之,就说明community已经超出了设备支持的最大长度。
这个脚本使用前面讲到的test.exp调用,调用方法是:
./test.exp -ssnmp.exp script
对它稍加修改,也可以直接在命令行中调用,此处不再赘述。

代码如下:

# $Id$

proc snmpCommTest {comm} {
    global g_devip

    spawn snmpget -c $comm -v 2c -r 2 $g_devip system.sysUpTime.0
    expect {
        "system.sysUpTime.0*" {
            return 1
        }
        "*Timeout*" {
            return 0
        }
    }

    return 1
}

set spawn_id [login $g_devip $g_user $g_passwd]
if {$spawn_id == 0} {
    errLog "login error\n"
    return 0
}

set cmdCommAdd "create snmp community %s rw\n"
set cmdCommDel "delete snmp community %s\n"
set cmdHostAdd "create snmp host ip 192.168.1.2 community %s\n"
set cmdHostDel "delete snmp host ip 192.168.1.2 community %s\n"
set comm ""

for {set i 1} {$i < 256} {incr i} {
    set comm "a$comm"
    set cmd [format $cmdCommAdd $comm]
    exp_send $cmd
    expect {
        "Error*" {
            errLog "create comm len $i error"
            continue
        }
        timeout {
            errLog "create comm len $i timeout"
            continue
        }
        "Entry Created"
    }
    set cmd [format $cmdHostAdd $comm]
    exp_send $cmd
    expect {
        "Error*" {
            errLog "create host error"
            continue
        }
        timeout {
            errLog "create host timeout"
            continue
        }
        "Entry Created"
    }

    set rc [snmpCommTest $comm]
    if {$rc == 0} {
        errLog "community len $i failed"
    }

    set cmd [format $cmdHostDel $comm]
    exp_send $cmd
    expect "Entry Deleted"
    set cmd [format $cmdCommDel $comm]
    exp_send $cmd
    expect "Entry Deleted"
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14780873/viewspace-374740/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/14780873/viewspace-374740/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
linux环境下的snmp测试脚本, Installing SNMPv2C Agent Conformance Test Package 2008/04/08 IPv6 Promotion Council Terminology =========== Tester Node (TN) A tester node for the conformance tests. Node Under Test (NUT) A testee node for the conformance tests. Network Under Test The network where the conformance tests are executed. Tester Interface The network interface of TN hooked up to the Network Under Test. Interface Under Test The network interface of NUT hooked up to the Network Under Test. Prerequisites ============= Prerequisites for TN: - The package supports FreeBSD 6.0-RELEASE or higher version. - The package can also coexist with FreeBSD version of KAME. Installing the package onto TN ============================== 0. Before Starting (A) You need to install following softwares. - Perl (Required version : 5.8.7 or higher) - Net-SNMP (Required version : 5.3.1 or higher) *** You can download it from the following URL: http://net-snmp.sourceforge.net/ - v6eval (Required version : 3.0.11 or higher) Please refer to 00README.v6eval in "v6eval" for more information. *** You can download it from the following URL: http://www.tahi.org/release/ - koi (Required version : 1.1.1 or higher) Please refer to README file in "koi" package for more information. *** You can download it from the following URL: http://www.tahi.org/release/ 1. Extracting ct package % tar zxvf ct-snmpv2c-ag-X.X.tar.gz 2. Copying ct package Copy ct directory to any directory you like. % cp -pR $ORGDIR/ct-snmpv2c-ag-X.X $SOMEWHERE/ct-snmpv2c-ag-X.X % chmod -R +w $SOMEWHERE/ct-snmpv2c-ag-X.X 4. Setup ct environment % (enable TN's ipv6 capibility) % cd $SOMEWHERE/ct-snmpv2c-ag-X.X % edit config.txt % make test [End of INSTALL]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值