2012-04-20 5 views
5

을 인식 할 수 없습니다 :PySNMP 내가 다음과 같은 간단한 스크립트를 사용하고 응답

from pysnmp.entity.rfc3413.oneliner import cmdgen 

errorIndication, errorStatus, errorIndex, \ 
varBindTable = cmdgen.CommandGenerator().bulkCmd(
      cmdgen.CommunityData('test-agent', 'public'), 
      cmdgen.UdpTransportTarget(('IP.IP.IP.IP', 161)), 
      0, 
      1, 
      (1,3,6,1,2,1,4,24,4,1,2,169,254) 
     ) 

if errorIndication: 
    print errorIndication 
else: 
    if errorStatus: 
     print '%s at %s\n' % (
      errorStatus.prettyPrint(), 
      errorIndex and varBindTable[-1][int(errorIndex)-1] or '?' 
      ) 
    else: 
     for varBindTableRow in varBindTable: 
      for name, val in varBindTableRow: 
       print '%s = %s' % (name.prettyPrint(), val.prettyPrint()) 

이 장치 반환 예상되는 결과에 명령 줄에서 snmpwalk를 사용. 그러나 스크립트는 제한 시간 전에 SNMP 응답을받지 못했습니다. 이 OID를 생략하면 모든 것이 잘 동작합니다. 우리가 볼 수 있듯이, 장치 반환 .1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0=[inetaddr len!=4]0.0.255.255.0.0.0.0를 응답하지만 아무 일도 일어나지 않고 pysnmp 그냥 또 다시이 OID의 값을 계속 시도

/usr/sbin/tcpdump -nn -vv -s0 -A host HOST and udp 

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes 

12:15:31.494920 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto: UDP (17), length: 77) IP.IP.IP.IP.47911 > IP.IP.IP.IP.161: [bad udp cksum 4b7d!] { SNMPv2c { GetBulk(34) R=8993731 N=0 M=1 .1.3.6.1.2.1.4.24.4.1.2.169.254 } } 
[email protected]@.I..]<..]</.'...9.S0/.....public."....;.......0.0...+..........).~.. 

12:15:31.495666 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto: UDP (17), length: 98) IP.IP.IP.IP.161 > IP.IP.IP.IP.47911: [udp sum ok] { SNMPv2c { GetResponse(55) R=8993731 .1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0=[inetaddr len!=4]0.0.255.255.0.0.0.0 } } 
[email protected]@.I..]</.]<....'.N.\0D.....public.7....;.......0)0'..+..........)[email protected] 

12:15:32.500226 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto: UDP (17), length: 77) IP.IP.IP.IP.47911 > IP.IP.IP.IP.161: [bad udp cksum 4b7d!] { SNMPv2c { GetBulk(34) R=8993731 N=0 M=1 .1.3.6.1.2.1.4.24.4.1.2.169.254 } } 
[email protected]@.I..]<..]</.'...9.S0/.....public."....;.......0.0...+..........).~.. 

12:15:32.500624 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto: UDP (17), length: 98) IP.IP.IP.IP.161 > IP.IP.IP.IP.47911: [udp sum ok] { SNMPv2c { GetResponse(55) R=8993731 .1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0=[inetaddr len!=4]0.0.255.255.0.0.0.0 } } 
[email protected]@.I..]</.]<....'.N.\0D.....public.7....;.......0)0'..+..........)[email protected] 

: 그래서 문제는이 OID에

여기 tcpdump를 통계입니다 .. snmpwalk이 응답을 IP ADDRESS 0.0.255.255

으로 인식 할 수 있습니까? 사전에 감사하고 나의 영어를 유감스럽게 생각한다.

답변

4

SNMP 에이전트가 깨진 SNMP 메시지를 생성하는 것 같습니다. IPv4 주소는 4 옥텟 길이이지만 에이전트는 8 옥텟 값을보고합니다.

SNMP RFC에 따라 pysnmp는 잘못된 형식의 SNMP 메시지를 삭제하고 올바른 응답을 얻기 위해 원래 요청을 몇 번 다시 시도합니다.

은 가능성이 더 이상 초기화에서 불과 네 개의 주요 옥텟을 복용하기 위해 당신이 실행시 IPADDRESS 클래스를 패치 할 수 특별히 잘못된 IP 주소 값 작업 pysnmp를 만들려면 :

>>> def ipAddressPrettyIn(self, value): 
... return origIpAddressPrettyIn(self, value[:4]) 
... 
>>> origIpAddressPrettyIn = v2c.IpAddress.prettyIn 
>>> v2c.IpAddress.prettyIn = ipAddressPrettyIn 
>>> 
>>> msg, rest = decoder.decode(wholeMsg, asn1Spec=v2c.Message()) 
>>> print msg.prettyPrint() 
Message: 
version='version-2' 
community=public 
data=PDUs: 
response=ResponsePDU: 
    request-id=6564368 
    error-status='noError' 
    error-index=0 
    variable-bindings=VarBindList: 
    VarBind: 
    name=1.3.6.1.2.1.4.24.4.1.2.169.254.0.0.0.0.255.255.0.0.0.0.0 
    =_BindValue: 
    value=ObjectSyntax: 
     application-wide=ApplicationSyntax: 
     ipAddress-value=0.0.255.255 
+0

다시 감사합니다 :) –

관련 문제