Search code examples
pythonsnmpnet-snmp

snmpwalk : get list of integers not string


In my python script I fetch 5 OID which return each an integer Here my code :

OIDs = []
res = []

OIs.append(netsnmp.VarList(netsnmp.Varbind('1.3.6.1.4.1.45.1.1.4.1')))
OIs.append(netsnmp.VarList(netsnmp.Varbind('1.3.6.1.4.1.45.1.1.4.2')))
OIs.append(netsnmp.VarList(netsnmp.Varbind('1.3.6.1.4.1.45.1.1.4.3')))
OIs.append(netsnmp.VarList(netsnmp.Varbind('1.3.6.1.4.1.45.1.1.4.4')))
OIs.append(netsnmp.VarList(netsnmp.Varbind('1.3.6.1.4.1.45.1.1.3.1')))

for i in range(len(OIDs)):
    res.append(netsnmp.snmpwlak(OIDs[i], Version = 2, DestHost='192.168.0.1', Community='public'))
return res

print res return me that list :

[('18',), ('13',), ('1',), ('2',), ('1',)]

All values returned by OID are integers

Qestion :

How can I get a list with only integers inside, like this :

[18, 13, 1, 2, 1]

Anyone know how to solve my problem ?


Solution

  • res = [('18',), ('13',), ('1',), ('2',), ('1',)]
    res = [int(x[0]) for x in res] ## [18, 13, 1, 2, 1]