title: Doing a complete nextCmd scan with PySNMP
body: <p>I'm trying to scan a device in my network with PySNMP and want to do a extensive walk through the MIB tree and see what I can find.
  For this I wrote a script, which works quite well, but it does not finish the task.</p>
  
  <pre><code>from pysnmp.entity.rfc3413.oneliner import cmdgen
  from os.path import exists
  import sys
  
  
      # Create command generator
      cmdGen = cmdgen.CommandGenerator()
  
      # Function definition
      def snmp_get_next(OID, target_IP, target_port, target):
  
          if exists(target):
              sys.exit("The file '%s' already exists!" % target)
          else: 
              target_file = open(target, 'w+')
  
          # Getting values
          errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
              cmdgen.CommunityData('public'),
              cmdgen.UdpTransportTarget((target_IP, target_port)),
              OID,
              cmdgen.MibVariable('IF-MIB', '').loadMibs(),
              lexicographicMode=True, maxRows=100,
              ignoreNonIncreasingOid=True
          )
  
          # Printing errors and OID_name to file
          if errorIndication:
              print(errorIndication)
          else:
              if errorStatus:
                  print('%s at %s' % (
                      errorStatus.prettyPrint(),
                      errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
                      )
                  )
              else:
                  for varBindTableRow in varBindTable:
                      for name, val in varBindTableRow:
                          target_file.write('- %s:\t OID: %s and value = %s\n' 
                                        % (OID, name.prettyPrint(), val.prettyPrint())
                                        )
          target_file.close()
          print('Writing successful!')
  
  
          sys.exit(0)
  
      # Execution of function
      snmp_get_next(
                    tuple(map(int,raw_input('OID Tuple:\t').split(','))), 
                    raw_input('Target IP:\t'), 
                    raw_input('Target Port:\t'), 
                    raw_input('Target File:\t')
                   )
  </code></pre>
  
  <p>So, when i execute the script with starting tuple 1,3,6,1,2,1,2,2,1,3 I get a file with about 100 entrys, the last entry has tuple 1,3,6,1,2,1,2,2,1,2,21. Now when I use this last tuple as starting tuple it still finds more. 
  Either I misunderstood something, or it does not what it's supposed to.</p>
  
  <p>UPDATE:</p>
  
  <p>I changed my code a bit and now it works almost like it's supposed to. The only problem is, that I can't leave out the "maxRows" parameter or else I get a timeout error message.</p>
  
  <pre><code>from pysnmp.entity.rfc3413.oneliner import cmdgen
  from os.path import exists
  import sys
  
  # Turn on debugging
  #debug.setLogger(debug.Debug('msgproc', 'secmod'))
  
  # Enter parameters
  target_IP           = raw_input('Target IP (192.168.13.100): ') or '192.168.13.100'
  target_port         = raw_input('Target port (161): ') or 161
  target_file_name    = raw_input('Target filename (.txt is added): ') + '.txt' 
  
  # Check for already existing file
  if exists(target_file_name):
      sys.exit("The file '%s' already exists!" % target_file_name)
  else: 
      target_file = open(target_file_name, 'w+')
  
  # Initialize counter to zero
  counter = 0
  
  # Create command generator
  cmdGen = cmdgen.CommandGenerator()
  
  # Get data
  
  errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
      cmdgen.CommunityData('public'),
      cmdgen.UdpTransportTarget((target_IP, target_port)),
      '1.3', # &lt;---- Does not seem perfect to me, but it works
      lexicographicMode=True, 
      maxRows=5000, #  &lt;---- Can't be left out, but I want to
      ignoreNonIncreasingOid=True,
      lookupNames=True, 
      lookupValues=True
  )
  
  # Print errors and values to file
  if errorIndication:
      print(errorIndication)
  else:
      # Print error messages
  
      if errorStatus:
          print('%s at %s' % (
              errorStatus.prettyPrint(),
              errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
              )
          )
      else:
          # Print values
          for varBindTableRow in varBindTable:
              for name, val in varBindTableRow:
                  counter += 1
                  target_file.write("(%s)\t start_OID: %s\tvalue =\t%s\n" % (counter, name.prettyPrint(), val.prettyPrint()))
  
          # Finish the operation                
          target_file.close()
          print('Writing to %s successful. %d lines have been written' % (target_file_name, counter))
          sys.exit(0)
  </code></pre>