我在网络上看了好几天,终于搞定了,不过才是简单的一点点,关于利用idsnmp来做trap我还不知道怎么做,下面我就给出这个代码,希望对使用这个东西的人有所帮助!unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient,
IdSNMP;type
TForm1 = class(TForm)
snmp: TIdSNMP;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
origOID:string;
i:integer;
begin
SNMP.Community := 'public';
SNMP.Host := '202.202.41.173';
SNMP.Query.Clear;
origOID := '1.3.6.1.2.1.2.2.1.16';
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
memo1.Lines.Add(SNMP.Reply.Value[I]);
SNMP.Query.Clear;
SNMP.Query.MIBAdd(SNMP.Reply.ValueOID[0], '');
SNMP.Query.PDUType := PDUGetNextRequest;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient,
IdSNMP;type
TForm1 = class(TForm)
snmp: TIdSNMP;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
origOID:string;
i:integer;
begin
SNMP.Community := 'public';
SNMP.Host := '202.202.41.173';
SNMP.Query.Clear;
origOID := '1.3.6.1.2.1.2.2.1.16';
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
memo1.Lines.Add(SNMP.Reply.Value[I]);
SNMP.Query.Clear;
SNMP.Query.MIBAdd(SNMP.Reply.ValueOID[0], '');
SNMP.Query.PDUType := PDUGetNextRequest;
end;
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货