Code: Alles auswählen
In [79]: a
Out[79]: OctetString('\x00\re[v\x1d')
In [80]: str(a)
Out[80]: '\x00\re[v\x1d'
Code: Alles auswählen
In [81]: a[0]
Out[81]: '\x00'
In [82]: map(ord, a)
Out[82]: [0, 13, 101, 91, 118, 29]
Code: Alles auswählen
In [79]: a
Out[79]: OctetString('\x00\re[v\x1d')
In [80]: str(a)
Out[80]: '\x00\re[v\x1d'
Code: Alles auswählen
In [81]: a[0]
Out[81]: '\x00'
In [82]: map(ord, a)
Out[82]: [0, 13, 101, 91, 118, 29]
Also reine Logik würde mir raten, mal das erste Objekt aus dieser Liste rauszuholen und anzuschauen. Vielleicht hat es ja interessante Attribute?herates hat geschrieben:ich bin nicht der spezi in python (wie auch nach 2 wochen). also pysnmp verwendet.. was bekomm ich? eine liste von listenobjekten mit der länge 1.
was soll ich den jetzt damit großartig anfangen?
Genau das hätte er schreiben können.Lies bitte erst einmal das Tutorial, und lerne, mit Listen und Objekten umzugehen.
wie ich verallgemeinerungen hasseweil ich mich auch Moderator schimpfe und diese bei dir offenbar unbeliebt sind.
Code: Alles auswählen
Python 2.4.3 (#1, Sep 8 2010, 11:38:44)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysnmp.entity.rfc3413.oneliner import cmdgen
>>> oid = (1, 3, 6, 1, 4, 1, 9, 9, 513, 1, 1, 1, 1, 2)
>>> ip="123.123.123.123"
>>> port=161
>>> community="dfsrtfwe"
>>> udpConnection = cmdgen.UdpTransportTarget((ip, port))
>>> snmpConnection = cmdgen.CommunityData('test-agent', community)
>>> varBindTable = cmdgen.CommandGenerator().nextCmd(snmpConnection, udpConnection, oid)
>>> type(varBindTable)
<type 'tuple'>
>>>>>> len(varBindTable)
4
# okay hier habe ich mich geirrt. varBindTable ist also ein Tupel. Die ersten 3 Elemente sind StatusCodes von der Abfrage. Das vierte:
>>> print varBindTable[3]
[[(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.15.247.72.161.96'), OctetString('\x00\re[v\x1d'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.15.247.72.163.16'), OctetString('\x00\re[v\x85'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.15.247.122.99.192'), OctetString('\x00\x0f\x90>:S'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.17.92.104.31.240'), OctetString('\x00\re[v\x1a'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.20.27.88.117.176'), OctetString('\x00\x14\x1c\xed/\xbc'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.23.223.167.243.144'), OctetString('\x00\x1b\xd5\x130\xb6'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.23.223.168.26.80'), OctetString('\x00\x1b\xd5\x13>\x18'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.25.169.253.113.240'), OctetString('\x00\x1a/\x83Tt'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.25.169.253.132.64'), OctetString('\x00\x1a/\x83V\xba'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.27.212.134.7.96'), OctetString('\x00\x0c\x85\xa8\x89\x88'))], [(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.28.88.175.138.112'), OctetString('\x00\x0c\x85\xf5\xb6\xe0'))]]
>>> tmp = varBindTable[3]
>>> type(tmp)
<type 'list'>
>>> len(tmp)
11
>>> tmp = tmp[1] # um mir mal eins rauszugreifen
>>> type(tmp)
<type 'list'>
>>> len(tmp)
1
>>> tmp = tmp[0]
>>> type(tmp)
<type 'tuple'> # okay ich gebe zu auch hier meine hausaufgaben nicht gemacht zu haben
>>> print tmp
(ObjectName('1.3.6.1.4.1.9.9.513.1.1.1.1.2.0.15.247.72.163.16'), OctetString('\x00\re[v\x85'))
>>> len(tmp)
2
>>> tmp = tmp[1]
>>> type(tmp)
<type 'instance'>
>>> print tmp
e[v