2012-02-13 87 views
0

我有以下的(工作)perl脚本:SNMP v3与NET :: SNMP工作,但snmpwalk/snmpget没有?

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 
#.... 

现在我想用snmpwalk的或相同的按键SNMPGET。对于这一点,我创建了一个snmp.conf文件中.snmp我的主目录包含以下内容组成:

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

当我看到它,我用的是相同的凭据的脚本和SNMPGET。为什么我会收到snmpget:身份验证失败(密码错误,社区或密钥)

+0

我曾经在一家使用Perl进行多厂商网络管理的公司工作。我的0.02美元就是存在足够的不一致性,如果某个SNMP客户端库可以使用某个SNMP客户端库而不是另一个,那么您应该不会感到过分惊讶,并且如果随机设备的SNMP代理是一件垃圾,那么双倍不会感到惊讶。 ;) – fennec 2012-02-15 03:05:44

回答

1

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

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

1

你的问题是你正在使用Net :: SNMP的认证密钥和命令行net-snmp工具的密码。根据您的Net :: SNMP使用情况,您实际上使用的是“本地化”密钥。这意味着您的snmp.conf文件的权限令牌为:

defAuthLocalizedKey 0xHEXSTRING 
defPrivLocalizedKey 0xHEXSTRING 

请参阅snmp.conf手册页以获取更多详细信息。