Recent

Author Topic: snmpwalk code?  (Read 3421 times)

vonskie

  • Full Member
  • ***
  • Posts: 184
snmpwalk code?
« on: June 22, 2017, 03:34:39 pm »
I have been using the Ararat Synapse snmpsend library and it does not have a snmpwalk function, has anyone coded this and would you please share.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: snmpwalk code?
« Reply #1 on: June 22, 2017, 03:47:30 pm »
Shouldn't you use SNMPGetNext for that?

Code: Pascal  [Select][+][-]
  1. {:A very useful function and example of its use would be found in the TSNMPSend
  2.  object. It implements basic GETNEXT method of the SNMP protocol. The MIB value
  3.  is located in the "OID" variable, and is sent to the requested "SNMPHost" with
  4.  the proper "Community" access identifier. Upon a successful retrieval, "Value"
  5.  will contain the information requested. If the SNMP operation is successful,
  6.  the result returns @true.}
  7. function SNMPGetNext(var OID: AnsiString; const Community, SNMPHost: AnsiString; var Value: AnsiString): Boolean;

(I thought snmpwalk just uses SNMPGetNext)

vonskie

  • Full Member
  • ***
  • Posts: 184
Re: snmpwalk code?
« Reply #2 on: June 22, 2017, 03:50:40 pm »
Not sure I will try it.. Thanks!


vonskie

  • Full Member
  • ***
  • Posts: 184
Re: snmpwalk code?
« Reply #3 on: June 22, 2017, 10:45:11 pm »
Well hell it works, but how do you know when your at the end of the MIB it just keeps going

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: snmpwalk code?
« Reply #4 on: June 22, 2017, 10:52:13 pm »
Well hell it works, but how do you know when your at the end of the MIB it just keeps going
Nope, the result becomes false. Then it stops...
Specialize a type, not a var.

vonskie

  • Full Member
  • ***
  • Posts: 184
Re: snmpwalk code?
« Reply #5 on: June 23, 2017, 09:11:38 pm »
Incase anyone else runs into this issue this is what I did and how I got it to work without walking the whole tree.

lMessage.Text := 'Getting MAC Port List...';


  baseoid := '1.3.6.1.2.1.17.4.3.1.2';
  oid := baseoid;

   walkmemo.Lines.Add('Port' + #9 + 'MAC');
  repeat

    snmpResult := SNMPGetNext(oid, snmpval, ipaddrval, s);
    if (SNMPResult = True) then
      begin

    if Pos(BaseOID, OID) <> 1 then
      break;

     mactemp:=midstr(oid,length(baseoid)+2,length(oid)-(length(baseoid)+1));

     List:=TStringList.Create;
     List.Delimiter:='.';
     List.DelimitedText:=mactemp;

     for macindex:=0 to 5 do
     begin
       if macindex=0 then
       begin

       macaddress:= inttohex( strtoint(list[macindex]),2);
       end
       else
       begin
       macaddress:=macaddress +':'+ inttohex( strtoint(list[macindex]),2);
       end;
      end;

     walkmemo.Lines.Add(s + #9 +   macaddress);
     application.processmessages;
     end;
  until not snmpresult;


  lMessage.Text := 'Complete!';
                                       



 

TinyPortal © 2005-2018