Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Indy-SNMP Sample

941 views
Skip to first unread message

Alex Chen

unread,
Jan 28, 2002, 11:12:03 AM1/28/02
to
In the indy 9.03B version has snmp component. but does anyone know how to
use this component?
Does anyone know where can I find the snmp sample program?

Regards,
Alex

Colin Wilson

unread,
Jan 28, 2002, 12:27:31 PM1/28/02
to
"Alex Chen" <alex...@seed.net.tw> wrote:

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

Сектор СА

unread,
Oct 6, 2022, 3:46:14 PM10/6/22
to
Just a little necromancy. 20 years later its looks like this (and working on lazarus)

var
Main: TMain;
IdSNMP1: TIdSNMP;
implementation
{$R *.lfm}

{ TMain }

procedure TMain.Button1Click(Sender: TObject);

var
eMIB: string;
begin
IdSNMP1 := TIdSNMP.Create;
eMIB := main.Mib.Text ;
idsnmp1.Active:=true;
idsnmp1.ReceiveTimeout:=5000;
IdSNMP1.Host := main.IP.Text;
IdSNMP1.Community := main.Community.text;
IdSNMP1.Port:=161;
IdSNMP1.Query.Clear;
idsnmp1.query.MIBOID.Add(eMIB);
IdSNMP1.Query.PDUType := PDUGetRequest;
idsnmp1.SendQuery;
try
if IdSNMP1.Reply.ValueCount>0 then begin
main.result2.lines.Add(idsnmp1.reply.Value[0]);
end;
finally
IdSNMP1.Free;
end;
end;

procedure TMain.Button2Click(Sender: TObject);
var
oid, origOid : string;
i : Integer;
begin
IdSNMP1 := TIdSNMP.Create;
IdSNMP1.Community := Community.Text; // defaults to 'public'
IdSNMP1.Host := IP.Text; // defaults to 127.0.0.1
oid := MIB.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;

try
while IdSNMP1.SendQuery do
begin
if Copy (IdSNMP1.Reply.MIBOID [0], 1, Length (origOID)) <> origOID
then
break;
for i := 0 to IdSNMP1.Reply.ValueCount - 1 do main.Result2.lines.add(IdSNMP1.Reply.value[i]);
for i := 0 to IdSNMP1.Reply.ValueCount - 1 do main.lvResults.Items.Add(IdSNMP1.Reply.value[i]);

//showresults; //почему то не работает если вызывать, но работает код выше
IdSNMP1.Query.Clear;
IdSNMP1.Query.MIBAdd(IdSNMP1.Reply.ValueOID [0], '');
IdSNMP1.Query.PDUType := PDUGetNextRequest
end
finally
Screen.Cursor := crDefault;
IdSNMP1.Free;
end
end;

Сектор СА

unread,
Oct 6, 2022, 3:51:30 PM10/6/22
to
> for i := 0 to IdSNMP1.Reply.ValueCount - 1 do main.lvResults.Items.Add(IdSNMP1.Reply.value[i]);

This is unused, sorry
0 new messages