Delphi SNMP

SNMP di Delphi XE2 menggunakan Indy. Berikut ini adalah contoh sederhana cara penggunaanya.

GET Request:

procedure TForm3.Button1Click(Sender: TObject);
var
  mib : string;
begin
  IdSNMP1 := TIdSNMP.Create;
  mib := '1.3.6.1.4.1.6247.24.1.2.3.1.0';
  try
    IdSNMP1.Host := '192.168.2.10';
    IdSNMP1.Community := 'wublic';
    IdSNMP1.Query.Clear;
    IdSNMP1.Query.PDUType := PDUGetRequest;
    IdSNMP1.Query.MIBAdd(mib,'');
    if IdSNMP1.SendQuery then
      Edit2.Text := IdSNMP1.Reply.MIBGet(mib);
  finally
    IdSNMP1.Free;
  end;
end;

GET Request bisa juga menggunakan QuickSend :

procedure TForm2.Button1Click(Sender: TObject);
begin
  IdSNMP1 := TIdSNMP.Create;
  try
    IdSNMP1.QuickSend('1.3.6.1.4.1.6247.24.1.2.3.1.0', 'wublic', '192.168.2.10', val);
    ShowMessage(val);
  finally
    IdSNMP1.Free;
  end;
end;


SET request:

procedure TForm3.Button2Click(Sender: TObject);
begin
  IdSNMP1 := TIdSNMP.Create;

  try
    IdSNMP1.Host := '192.168.2.10';
    IdSNMP1.Community := 'private';
    IdSNMP1.Query.Clear;
    IdSNMP1.Query.PDUType := PDUSetRequest;                          IdSNMP1.Query.MIBAdd('1.3.6.1.4.1.6247.24.1.2.3.1.0', '71000000', 2);
    if IdSNMP1.SendQuery then ShowMessage('Success');
  finally
    IdSNMP1.Free;
  end;

end;