Link to home
Start Free TrialLog in
Avatar of beer9
beer9Flag for India

asked on

How to convert a OID into name in Python

Hello,

I have a OID as below
30.118.115.58.115.105.110.103.108.101.58.116.101.115.116.45.109.97.99.104.105.110.101.58.104.116.116.112.64.56.48

Open in new window


I would like to know how can I convert it to it's name using python? I do not want to make any network or localhost call.

this OID is mapped to one of the VSERVER's Name in NetScaler.
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of beer9

ASKER

Hi @aikimark,

Thanks for your response, I am wondering what is the \xle before the actual vserver's name

also based upon your example I tried to do it with below OID:

31.73.78.97.121.105.103.108.121.98.121.118.98.53.111.52.100.108.103.114.109.97.114.100.115.104.120.97.100.120.100.48

Open in new window

and I didn't get expected response

>>> a = '31.73.78.97.121.105.103.108.121.98.121.118.98.53.111.52.100.108.103.114.109.97.114.100.115.104.120.97.100.120.100.48'
>>> ''.join([chr(int(x)) for x in a.split('.')])
'\x1fINayiglybyvb5o4dlgrmardshxadxd0'

Open in new window


I was expecting vs:single:test-machine-vip-tier1:http@80

appreciate your suggestion here
the period-delimited numbers are ASCII character values.  Since there is no equivalent character to represent the value of 30 or 31, Pyton converts those characters when it  displays or prints them.  I don't know why your second test string produced such weird results.
Avatar of beer9

ASKER

Thanks @aikimark for such quick response.

I appreciate any suggestion on where to look for ( any python module or function ) to convert \x1fINayiglybyvb5o4dlgrmardshxadxd0 to vs:single:test-machine-vip-tier1:http@80

any suggestion on what kind of encoding or conversion it could be? Thanks in advance
Avatar of beer9

ASKER

one unique things I see here is that if length of character of a vserver name is equal or more than 32 then only it gives weird result
after a little research, the first number is the length of the remaining character string
Avatar of beer9

ASKER

This is what I find after a little research in reverse engineering

vs:single:test-machine-vip-tier1:http@80

Open in new window


will convert to md5 hash

0023b370 b886effc cb4406e2 f25c30ee

Open in new window


and it's will converted to (Transform a 8 digits hex string (32 bits) a into a 32 bit unsigned long, little-endian)

1890788096 4243556024 3792061643 3996146930 

Open in new window


and using below script it will be converted as per ascii table

response = ''
ascii_map = 'abcdefghijklmnopqrstuvwxyz012345'
for j in range(7):
    response += ascii_map[(int('3996146930') >> (5*j)) & 31]
print response

Open in new window


 
ayiglyb yvb5o4d lgrmard shxadxd

Open in new window


Then Append IN if vserver's name is >=32 and and append last character of vserver's name , which is 0

INayiglybyvb5o4dlgrmardshxadxd0

Open in new window


and then it will be converted to as per ascii table

31.73.78.97.121.105.103.108.121.98.121.118.98.53.111.52.100.108.103.114.109.97.114.100.115.104.120.97.100.120.100.48

Open in new window

also as you mentioned it appends 31 as count of remaining chracter which makes it a total size of 32
Avatar of beer9

ASKER

since there is hashing algorithm (md5) involved, making it difficult ( impossible? ) to change from OID to actual name
Correct.  You have posted two OID strings.  The first one was simple to decode and gave you almost expected results.  Is the second string from a different source, since it goes through a hash process?
That bit of Python code will not produce the output string.  It only produces a 7 character (long) string.