2012-02-13 41 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手冊頁以獲取更多詳細信息。