Regards,
Alex
Hi Alex,
I'e recently joined the Indy core team, with responisbility for SNMP.
The latest version of IdSNMP isn't in Indy 9.0.3 yet. But you can download
it from Nevrona's FTP site at <ftp://indy90:ind...@ftp.nevrona.com/>
As well as downloading IdSNMP.pas, you will also need IdASN1UTIL.pas.
This version of IdSNMP.pas fixes a number of bugs with the version that's
in 9.0.3B, as well as providing some additional functionaility.
I also submitted a demo program for SNMP that does simple getting and
walking. I don't think you can download that from the FTP site yet.
Here are some snippets from the demo. I hope this helps. Good luck with
your project.
// SNMP Get
procedure TForm1.btnGetClick(Sender: TObject);
begin
IdSNMP1.Community := edCommunity.Text; // defaults to 'public'
IdSNMP1.Host := edServerAddress.Text; // defaults to 127.0.0.1
IdSNMP1.Query.Clear;
IdSNMP1.Query.MIBAdd(cbMib.Text, ''); // defaults to 1.3.6.1.2.1.
1.0
IdSNMP1.Query.PDUType := PDUGetRequest;
IdSNMP1.SendQuery;
ShowResults;
end;
// SNMP Walk
procedure TForm1.btnWalkClick(Sender: TObject);
var
oid, origOid : string;
begin
IdSNMP1.Community := edCommunity.Text; // defaults to 'public'
IdSNMP1.Host := edServerAddress.Text; // defaults to 127.0.0.1
oid := cbMIB.Text; //
defaults to 1.3.6.1.2.1.1.1.0
if Copy (oid, Length (oid) - 1, 2) = '.0' then // strip trailing
'.0'
oid := Copy (oid, 1, Length (oid) - 2);
origOID := oid;
IdSNMP1.Query.Clear;
IdSNMP1.Query.MIBAdd(oid, '');
IdSNMP1.Query.PDUType := PDUGetNextRequest;
Screen.Cursor := crHourGlass;
lvResults.Items.BeginUpdate;
try
while IdSNMP1.SendQuery do
begin
if Copy (IdSNMP1.Reply.MIBOID [0], 1, Length (origOID)) <> origOID
then
break;
ShowResults;
IdSNMP1.Query.Clear;
IdSNMP1.Query.MIBAdd(IdSNMP1.Reply.ValueOID [0], '');
IdSNMP1.Query.PDUType := PDUGetNextRequest
end
finally
lvResults.Items.EndUpdate;
Screen.Cursor := crDefault
end
end;
// And here's ShowResults - which is called from the two functions above to
populates a 3 column report mode list view.
procedure TForm1.ShowResults;
var
i : Integer;
begin
lvResults.Items.BeginUpdate;
try
for i := 0 to IdSNMP1.Reply.ValueCount - 1 do
with lvResults.Items.Add do
begin
Caption := IdSNMP1.Reply.ValueOID [i];
SubItems.Add(idSNMP1.Reply.Value [i]);
SubItems.Add(SNMPTypeToStr (idSNMP1.Reply.ValueType [i]))
end
finally
lvResults.Items.EndUpdate
end
end;
Colin
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm
Posted with XanaNews