一个程序,可以正常获取MIB库中的数据。代码如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient, IdSNMP,
  StdCtrls;type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    SNMP: TIdSNMP;
    IP: TEdit;
    Community: TEdit;
    OID: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementationuses StrUtils;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  origOID: string;
  i: integer;
begin
  SNMP.Community := Community.Text;
  SNMP.Host := IP.Text;
  SNMP.Query.Clear;
  origOID := OID.Text;
  SNMP.Query.MIBAdd(origOID, '');
  SNMP.Query.PDUType := PDUGetNextRequest;
  while SNMP.SendQuery do
  begin
    if Copy(SNMP.Reply.MIBOID[0], 1, Length(origOID)) <> origOID then
      Break;
    for I := 0 to SNMP.Reply.ValueCount - 1 do
    begin
      memo1.Lines.Add(SNMP.Reply.MIBOID[0] + ':' + SNMP.Reply.Value[I]);
    end;
    SNMP.Query.Clear;
    SNMP.Query.MIBAdd(SNMP.Reply.ValueOID[0], '');
    SNMP.Query.PDUType := PDUGetNextRequest;
  end;
end;但在Bridge-MIB(Rfc-1493)中定义的
.iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dBase.dot1dBaseBridgeAddress代表设备自身MAC地址,其ObjectID值为:.1.3.6.1.2.1.17.1.1
却不能正常获取返回值,不知道返回值的格式是什么。忘大侠们指教!
另外,.iso.org.dod.internet.mgmt.mib-2.dot1dBridge.dot1dTp.dot1dTpFdbTable.dot1dTpFdbEntry.dot1dTpFdbAddress代表设备下连端口学习MAC地址,其ObjectID值为:.1.3.6.1.2.1.17.4.3.1.1也不能正常返回值,一定请大家帮帮忙,在线等!谢谢了

解决方案 »

  1.   

    结果自己搞定了,Trace一遍
    SNMP.SendQuery
    reply.DecodeBuf
    Sv := ASNItem(Pos, buffer, vt);
          ASN1_OCTSTR, ASN1_OPAQUE:
            begin
              for n := 1 to ASNSize do
              begin
                c := Char(Buffer[Start]);
                Inc(Start);
                if c <> #0 then begin
                  s := s + c;
                end;
              end;
              Result := s;
            end;
    就是这里出问题了,c := Char(Buffer[Start]);s := s + c;
    两个Char后16进制变成了一个2字节字符,所以Snmp.Reply.Value出来的是两个Char组合成的字符串。
    把Value重新变成2位16进制字符后即可得出正确输出
    function StrToHex(Str: string): string;
    var
      i: integer;
    begin
      if Result = '' then Exit;
      try
        for i := 0 to 5 do
          Result := Result + IntToHex(ord(Str[i]), 2);
      except
        Result := Str;
      end;
    end;
      

  2.   

    Function StrToHex(Str: string): string; 
    var 
      i: integer; 
    begin 
      if Result =  ' ' then Exit; //这一句是用来做什么?
     try 
        for i := 0 to 5 do 
          Result := Result + IntToHex(ord(Str[i]), 2); 
      except 
        Result := Str; 
      end; 
    end;
      

  3.   

    楼主,能否借你程序俺学习学习 
    邮箱:
    [email protected]
    不管给不给 先谢谢啦 呵呵