Hi all,
I am able to successfully run an snmpwalk against localhost and one
of my servers. But for naught, I cant get idSNMP to do the same.
Here is the command ....
snmpwalk -r:127.0.0.1 -v:2c -t:10 -c:public -os:.1.3.6.1.2 -op:.1.3.6.1.3
Here is my code.....
void __fastcall TServerForm1::Button4Click(TObject *Sender)
{
IdSNMP1->Active = true;
IdSNMP1->Query->Clear();
IdSNMP1->Community = CommunityEdit1->Text;
IdSNMP1->Query->Host = IPTarget1->Text;
IdSNMP1->Query->Version = 2;
IdSNMP1->Query->Port = 161;
IdSNMP1->Query->MIBAdd("1.3.6.1.2", "");
IdSNMP1->Query->PDUType = PDUGetRequest;
if (IdSNMP1->SendQuery())
{
if (IdSNMP1->Reply->ValueCount > 0)
{
for (int i=0; iReply->ValueCount; i++)
{
AnsiString A = "Value :"; A += IdSNMP1->Reply->Value[i];
Memo1->Lines->Add(A);
}
}
}
IdSNMP1->Active = false;
Got it.....however this only works with SNMP Version 1.
Version 2 can do a bulk walk, which is fast.
But this v1 thing is a query-by-query walk, kind slow.
Any help on a version 2(c) walker would be nice.
void __fastcall TModifyServForm1::Button4Click(TObject *Sender)
{
IdSNMP1->Active = true;
int SNMPVer = 2;
if (SNMPv1->Checked == true) SNMPVer = 1; // Only works here...
if (SNMPv2->Checked == true) SNMPVer = 2;
if (SNMPv3->Checked == true) SNMPVer = 3;
IdSNMP1->Community = CommunityEdit1->Text;
IdSNMP1->Query->Clear();
IdSNMP1->Query->Host = IPTarget1->Text;
IdSNMP1->Query->Version = SNMPVer;
IdSNMP1->Query->Port = 161;
AnsiString oid, oldoid;
oid = OIDEdit1->Text;
IdSNMP1->Query->MIBAdd(oid, "");
IdSNMP1->Query->PDUType = PDUGetNextRequest;
Screen->Cursor = crHourGlass;
bool OK = IdSNMP1->SendQuery();
while (OK == true)
{
for (int i=0; iReply->ValueCount; i++)
{
AnsiString A = "Value : ";
A += IdSNMP1->Reply->MIBOID[i].Strings[i];
A += " : ";
A += IdSNMP1->Reply->Value[i];
Memo1->Lines->Add(A);
}
oldoid = oid;
oid = IdSNMP1->Reply->MIBOID[0].Strings[0];
if (oid != oldoid)
{
IdSNMP1->Query->Clear();
IdSNMP1->Query->Host = IPTarget1->Text;
IdSNMP1->Query->Version = SNMPVer;
IdSNMP1->Query->Port = 161;
IdSNMP1->Query->MIBAdd(oid, "");
IdSNMP1->Query->PDUType = PDUGetNextRequest;
OK = IdSNMP1->SendQuery();
}
else
{
OK = false;
}
}
IdSNMP1->Active = false;
Screen->Cursor = crDefault;
On 20/06/2014 11:54 PM, Colin Maharaj wrote:
> Hi all,
> I am able to successfully run an snmpwalk against localhost and one
> of my servers. But for naught, I cant get idSNMP to do the same.
>
> Here is the command ....
>
> snmpwalk -r:127.0.0.1 -v:2c -t:10 -c:public -os:.1.3.6.1.2 -op:.1.3.6.1.3
>
> Here is my code.....
>
> void __fastcall TServerForm1::Button4Click(TObject *Sender)
> {
> IdSNMP1->Active = true;
> IdSNMP1->Query->Clear();
> IdSNMP1->Community = CommunityEdit1->Text;
> IdSNMP1->Query->Host = IPTarget1->Text;
> IdSNMP1->Query->Version = 2;
> IdSNMP1->Query->Port = 161;
>
> IdSNMP1->Query->MIBAdd("1.3.6.1.2", "");
> IdSNMP1->Query->PDUType = PDUGetRequest;
>
> if (IdSNMP1->SendQuery())
> {
> if (IdSNMP1->Reply->ValueCount > 0)
> {
> for (int i=0; iReply->ValueCount; i++)
> {
> AnsiString A = "Value :"; A += IdSNMP1->Reply->Value[i];
> Memo1->Lines->Add(A);
> }
> }
> }
>
> IdSNMP1->Active = false;
>
Colin wrote:
> I am able to successfully run an snmpwalk against localhost and one
> of my servers. But for naught, I cant get idSNMP to do the same.
Did you try using a packet sniffer, like Wireshark, to compare and look for
any differences between the packets that SNMPWalk sends versus the packets
that TIdSNMP sends?
> Here is the command ....
>
> snmpwalk -r:127.0.0.1 -v:2c -t:10 -c:public -os:.1.3.6.1.2 -op:.1.3.6.1.3
> IdSNMP1->Active = true;
Why are you doing that? Get rid of it.
> IdSNMP1->Query->MIBAdd("1.3.6.1.2", "");
Notice the leading periods in the OIDs you are passing to snmpwalk. Did
you try including the leading periods in the OIDs you give to TIdSNMP?
You are also only querying 1 OID, but you query 2 OIDs with snmpwalk. You
can request multiple OIDs at a time with TIdSNMP.
--
Remy Lebeau (TeamB)