#!/usr/bin/env python
"""
css-oid.py
for encoding / decoding the name parts of Cisco CSS OIDs
as one might encounter with snmpget / snmpwalk
"""
import sys
def txt2oid(txt):
l=len(txt)
out="%s" % l
i=0
while (i<l):
c=txt[i]
out="%s.%s" % (out,ord(c))
i=i+1
return out
def oid2txt(oid):
l=9999
liste=oid.split('.')
if (liste[0] =="") or (chr(int(liste[0]))<32):
l=liste[0]
liste=liste[1:]
out=""
restliste=[]
if (int(liste[0]) < 65):
l=int(liste[0])
restliste=liste[l+2:]
liste=liste[1:l+1]
restoid=string.join(restliste,'.')
for item in liste:
item=int(item)
out="%s%s" % (out,chr(item))
if (len(restliste)>0):
out=out + " " + oid2txt(restoid)
return out
if __name__ == '__main__':
scriptname=sys.argv[0]
input=sys.argv[1]
if (input[0].isdigit() or input[0] =='.'):
print oid2txt(input)
else:
print txt2oid(input)
# the end
Verwendung:
$ css-oid.py Beispiel 8.66.101.105.115.112.105.101.108
oder andersrum:
$ css-oid.py 8.66.101.105.115.112.105.101.108 Beispiel $ css-oid.py 5.79.119.110.101.114.7.86.73.80.114.117.108.101 Owner VIPrule
Zusammenhängen:
1.3.6.1.4.1.9.9.368.1.25.2.1.15 = "number of bytes passed using content rules of this owner" 1)8.66.101.105.115.112.105.101.108 = "Beispiel" → Owner$ snmpget -v1 -On -c public css07.unixwitch.de 1.3.6.1.4.1.9.9.368.1.25.2.1.15.8.66.101.105.115.112.105.101.108 .1.3.6.1.4.1.9.9.368.1.25.2.1.15.8.66.101.105.115.112.105.101.108 = Counter32: 205197490
Zusammenhängen:
1.3.6.1.4.1.9.9.368.1.16.4.1.25 = "number of bytes passed using content rule" 2)$ css-oid.py TheOwner
→
8.84.104.101.79.119.110.101.114$ css-oid.py example.com
→
11.101.120.97.109.112.108.101.46.99.111.109snmpget -v1 -On -c public css07.unixwitch.de 1.3.6.1.4.1.9.9.368.1.16.4.1.25.8.84.104.101.79.119.110.101.114.11.101.120.97.109.112.108.101.46.99.111.109 .1.3.6.1.4.1.9.9.368.1.16.4.1.25.8.84.104.101.79.119.110.101.114.11.101.120.97.109.112.108.101.46.99.111.109 = Counter32: 3888751450
gilt für alle Tipps, Tricks & Spickzettel:
dies sind einfache, teils banale Notizen für meinen persönlichen Gebrauch,
die hier eher zufällig auch öffentlich lesbar sind
(vielleicht hilft es ja jemandem weiter). Verwendung auf eigene Gefahr
Fehler-Hinweise, Dankesschreiben , etc. bitte an: web.25@unixwitch.de
weitere Tools / Spickzettel