title: How to get data from SNMP with python?
body: <p>How to get value mac and vlan from fdb table uses python? <br>
  In bash snmpwalk work fine:
  </p>
  
  <pre><code>snmpwalk -v2c -c pub 192.168.0.100 1.3.6.1.2.1.17.7.1.2.2.1.2
  </code></pre>
  
  <p>pysnmp:
  </p>
  
  <pre><code>import os, sys
  import socket
  import random
  from struct import pack, unpack
  from datetime import datetime as dt
  
  from pysnmp.entity.rfc3413.oneliner import cmdgen
  from pysnmp.proto.rfc1902 import Integer, IpAddress, OctetString
  
  ip='192.168.0.100'
  community='pub'
  value=(1,3,6,1,2,1,17,7,1,2,2,1,2)
  
  generator = cmdgen.CommandGenerator()
  comm_data = cmdgen.CommunityData('server', community, 1) # 1 means version SNMP v2c
  transport = cmdgen.UdpTransportTarget((ip, 161))
  
  real_fun = getattr(generator, 'getCmd')
  res = (errorIndication, errorStatus, errorIndex, varBinds)\
      = real_fun(comm_data, transport, value)
  
  if not errorIndication is None  or errorStatus is True:
         print "Error: %s %s %s %s" % res
  else:
         print "%s" % varBinds
  </code></pre>
  
  <blockquote>
    <p>output: [(ObjectName(1.3.6.1.2.1.17.7.1.2.2.1.2), NoSuchInstance(''))]</p>
  </blockquote>
  
  <pre class="lang-python prettyprint-override"><code>import netsnmp
  
  def getmac():
      oid = netsnmp.VarList(netsnmp.Varbind('.1.3.6.1.2.1.17.7.1.2.2.1.2'))
      res = netsnmp.snmpgetbulk(oid, Version = 2, DestHost='192.168.0.100',
                             Community='pub')
      return res
  
  print getmac()
  </code></pre>
  
  <blockquote>
    <p>output: ('27', '27', '25', '27', '27', '27', '24', '27', '25', '18', '4',
    '27', '25', '27', '27', '25', '27', '27', '27', '27', '27', '27',
    '27', '27', '27', '27', '27', '27', '27', '27', '27', '27', '23',
    '25', '27', '27', '27', '25', '27', '25', '27', '27', '25', '27',
    '27', '27', '27', '27', '27', '27', '27', '27', '25', '27', '27',
    '27', '27', '27', '27', '27', '27', '27', '27', '27', '27', '25',
    '25', '25', '7', '27', '27', '9', '25', '27', '20', '19', '27', '27',
    '27', '27', '27', '27', '27', '27', '27', '27', '27', '27', '27',
    '27', '11', '25', '27', '27', '27', '27', '27', '27', '27', '27',
    '27', '27', '27', '27', '27', '27', '25', '27', '27', '27', '27',
    '27', '27', '27', '27', '27', '2', '27', '5', '27', '0', '27', '27',
    '27', '27', '27')</p>
  </blockquote>
  
  <p>Firs script(pysnmp) return NoSuchInstance. Second script(netsnmp) return list of ports but without mac and vlan. What wrong?</p>