uses IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient, IdSNMP;
{$R *.dfm}
procedure TForm1.btnQueryClick(Sender: TObject);
var
Snmp: TIdSNMP;
MibIndex: Integer;
MibValues : TStringList;
MibLabel :
string;
ValIndex : Integer;
begin
Snmp := TIdSNMP.Create(
nil);
MibValues := TStringList.Create;
try
Snmp.Query.Host := edtIp.Text;
Snmp.Query.Community := '
public';
Snmp.Query.PDUType := PDUGetRequest;
InitMibValues(MibValues);
for MibIndex := 0
to MibValues.Count -1
do
begin
Snmp.Query.MIBOID.Clear;
MibLabel := MibValues.Names[MibIndex];
Snmp.Query.MIBAdd(MibValues.ValueFromIndex[MibIndex], '
');
if Snmp.SendQuery
then
begin
for ValIndex := 0
to Snmp.Reply.ValueCount - 1
do
MemoResult.Lines.Add(Format('
%-20s: %s', [MibLabel,
Snmp.Reply.Value[0]]));
end;
end;
finally
MibValues.Free;
Snmp.Free;
end;
end;
procedure TForm1.InitMibValues(AList: TStrings);
const
PrintPrefix = '
1.3.6.1.2.1.';
var
i : integer;
begin
AList.Values['
Geräteinformation'] := '
1.1.0';
AList.Values['
Gesamtseiten'] := '
43.10.2.1.4.1.1';
AList.Values['
Tonerstand 1'] := '
43.11.1.1.9.1.1';
AList.Values['
Tonerstand 2'] := '
43.11.1.1.9.1.2';
AList.Values['
Tonerstand 3'] := '
43.11.1.1.9.1.3';
AList.Values['
Tonerstand 4'] := '
43.11.1.1.9.1.4';
for i := 0
to AList.Count-1
do
begin
AList.ValueFromIndex[i] := PrintPrefix + AList.ValueFromIndex[i];
end;
end;