6

我尝试修改从http://synapse.ararat.cz/files/contrib/Trap.zip下载的 TrapSend.dpr 示例项目,以发送 SNMP v2 陷阱但没有成功。注意:我能够使用示例成功发送 SNMP v1 陷阱。

这是 SNMPTrap.pas 中的原始函数 SendTrap:

function SendTrap(Dest, Source, Enterprise, Community: string;
  Generic, Specific, Seconds: integer; MIBName, MIBValue: string; MIBtype:integer): integer;
var
  SNMP: TTrapSNMP;
begin
  SNMP := TTrapSNMP.Create;
  try
    SNMP.SNMPHost := Dest;
    SNMP.Trap.TrapHost := Source;
    SNMP.Trap.Enterprise := Enterprise;
    SNMP.Trap.Community := Community;
    SNMP.Trap.GenTrap := Generic;
    SNMP.Trap.SpecTrap := Specific;
    SNMP.Trap.TimeTicks := Seconds;
    SNMP.Trap.MIBAdd(MIBName,MIBValue,MIBType);
    Result := SNMP.Send;
  finally
    SNMP.Free;
  end;
end;

在阅读了http://en.it-usenet.org/thread/14303/3313/中的示例后,我将 SNMPTrap.pas 修改为以下内容以发送通用的 linkdown SNMP v2 陷阱,但它不起作用:

function SendTrap(Dest, Source, Enterprise, Community: string;
  Generic, Specific, Seconds: integer; MIBName, MIBValue: string; MIBtype:integer): integer;
var
  SNMP: TTrapSNMP;
begin
  SNMP := TTrapSNMP.Create;
  try
    SNMP.SNMPHost := Dest;
  //  SNMP.Trap.TrapHost := Source;
  //  SNMP.Trap.Enterprise := Enterprise;
    SNMP.Trap.Community := Community;
  //  SNMP.Trap.GenTrap := Generic;
  //  SNMP.Trap.SpecTrap := Specific;
   // SNMP.Trap.TimeTicks := Seconds;

  SNMP.Trap.Version := SNMP_V2C;
  SNMP.Trap.PDUType := PDUTrapV2;

   // SNMP.Trap.MIBAdd(MIBName,MIBValue,MIBType);
    SNMP.Trap.MIBAdd('1.3.6.1.2.1.1.3.0','0',ASN1_TIMETICKS);
    SNMP.Trap.MIBAdd('1.3.6.1.6.3.1.1.4.1.0','1.3.6.1.6.3.1.1.5.3',ASN1_OBJID);
    Result := SNMP.Send;
  finally
    SNMP.Free;
  end;
end;

Wireshark 返回以下错误:

No.     Time           Source                Destination           Protocol Length Info
  50494 2016.821366000 192.168.0.125         192.168.0.10          SNMP     117    snmpV2-trap

Frame 50494: 117 bytes on wire (936 bits), 117 bytes captured (936 bits) on interface 0
Ethernet II, Src: IntelCor_0b:d9:b8 (00:24:d7:0b:d9:b8), Dst: Hewlett-_48:5c:54 (00:23:7d:48:5c:54)
Internet Protocol Version 4, Src: 192.168.0.125 (192.168.0.125), Dst: 192.168.0.10 (192.168.0.10)
User Datagram Protocol, Src Port: 63309 (63309), Dst Port: snmptrap (162)
Simple Network Management Protocol
    version: v2c (1)
    community: public
    data: snmpV2-trap (7)
        snmpV2-trap
            BER Error: Wrong field in sequence  expected class:UNIVERSAL(0) tag:2(INTEGER) but found class:UNIVERSAL(0) tag:6
                [Expert Info (Warn/Malformed): BER Error: Wrong field in sequence]
                    [Message: BER Error: Wrong field in sequence]
                    [Severity level: Warn]
                    [Group: Malformed]
            BER Error: Wrong field in sequence  expected class:UNIVERSAL(0) tag:2(INTEGER) but found class:APPLICATION(1) tag:0
                [Expert Info (Warn/Malformed): BER Error: Wrong field in sequence]
                    [Message: BER Error: Wrong field in sequence]
                    [Severity level: Warn]
                    [Group: Malformed]
            error-index: 0
            BER Error: Wrong field in sequence  expected class:UNIVERSAL(0) tag:16(SEQUENCE) but found class:UNIVERSAL(0) tag:2
                [Expert Info (Warn/Malformed): BER Error: Wrong field in sequence]
                    [Message: BER Error: Wrong field in sequence]
                    [Severity level: Warn]
                    [Group: Malformed]
            BER Error: This field lies beyond the end of the known sequence definition.
                [Expert Info (Warn/Malformed): BER Error: Unknown field in Sequence]
                    [Message: BER Error: Unknown field in Sequence]
                    [Severity level: Warn]
                    [Group: Malformed]
            BER Error: This field lies beyond the end of the known sequence definition.
                [Expert Info (Warn/Malformed): BER Error: Unknown field in Sequence]
                    [Message: BER Error: Unknown field in Sequence]
                    [Severity level: Warn]
                    [Group: Malformed]

为了比较,我包含了一个格式正确的 v2 SNMP 陷阱(我使用 ireasoning 的陷阱发送器发送)。

No.     Time           Source                Destination           Protocol Length Info
     54 7.697996000    192.168.0.125         192.168.0.10          SNMP     111    snmpV2-trap SNMPv2-MIB::sysUpTime.0 SNMPv2-MIB::snmpTrapOID.0

Frame 54: 111 bytes on wire (888 bits), 111 bytes captured (888 bits) on interface 0
Ethernet II, Src: IntelCor_0b:d9:b8 (00:24:d7:0b:d9:b8), Dst: Hewlett-_48:5c:54 (00:23:7d:48:5c:54)
Internet Protocol Version 4, Src: 192.168.0.125 (192.168.0.125), Dst: 192.168.0.10 (192.168.0.10)
User Datagram Protocol, Src Port: 53423 (53423), Dst Port: snmptrap (162)
Simple Network Management Protocol
    version: v2c (1)
    community: public
    data: snmpV2-trap (7)
        snmpV2-trap
            request-id: 75820535
            error-status: noError (0)
            error-index: 0
            variable-bindings: 2 items
                SNMPv2-MIB::sysUpTime.0 (1.3.6.1.2.1.1.3.0): 0
                    Object Name: 1.3.6.1.2.1.1.3.0 (SNMPv2-MIB::sysUpTime.0)
                    Value (Timeticks): 0
                SNMPv2-MIB::snmpTrapOID.0 (1.3.6.1.6.3.1.1.4.1.0): 1.3.6.1.6.3.1.1.5.3 (IF-MIB::linkDown)
                    Object Name: 1.3.6.1.6.3.1.1.4.1.0 (SNMPv2-MIB::snmpTrapOID.0)
                    Value (OID): 1.3.6.1.6.3.1.1.5.3 (IF-MIB::linkDown)
4

0 回答 0