0

I have the following (working) perl script:

use Net::SNMP;

 # create session to the host
 my ($session, $error) = Net::SNMP->session(
                -hostname => $hostname,
                -version => 'snmpv3',
                -username => 'my_user_name',
                -authkey => 'my_authkey',#actually, here stands the real authkey as configured on the switch
                -privkey => 'my_privkey',#same as on switch
                -authprotocol => 'sha',
                -privProtocol => 'des'
        );
        if (!defined($session)) {
            print $error . "\n";
                last;
        }

        # retrieve a table from the remote agent
        my $result = $session->get_table(
                -baseoid => $MAC_OID
        );

        if (!defined($result)) {
                print $session->error . "\n";
                $session->close;
                last;
        }
#print out the result of the snmp query
#....

Now I wanted to use snmpwalk or snmpget with the same keys. For that, I created a snmp.conf file in .snmp of my home directory with the following content:

defSecurityName my_user_name
defContext ""
defAuthType SHA
defSecurityLevel authPriv
defAuthPassphrase my_auth_key here
defVersion 3
defPrivPassphrase my_privkey here
defPrivType DES

As I see it, I use the same credentials in the script and for snmpget. Why do I get snmpget: Authentication failure (incorrect password, community or key) ?

4

2 回答 2

1

您的问题是您正在使用 Net::SNMP 的身份验证密钥和命令行 net-snmp 工具的密码。根据您的 Net::SNMP 使用情况,您实际上是在使用“本地化”密钥。这意味着您的 snmp.conf 文件的正确标记是:

defAuthLocalizedKey 0xHEXSTRING
defPrivLocalizedKey 0xHEXSTRING

有关详细信息,请参阅 snmp.conf 手册页。

于 2012-02-16T21:02:33.057 回答
1

这取决于您使用的 snmpget 和 snmpset 版本。当我针对基于 C# 的 SNMP 代理http://sharpsnmplib.codeplex.com测试旧版本的 net-snmp 时,我注意到对于 SHA 身份验证模式 + DES 隐私模式,一个错误阻止了 net-snmp 命令行工具生成正确的消息字节(加密错误,因此没有代理可以解密它)。

我的建议是您尝试使用 Net::SNMP 代替,就像您发现的那样,它不受相同错误的影响。

于 2012-02-15T02:56:35.313 回答