开发者

Encode and pad netbios name using python

开发者 https://www.devze.com 2023-01-12 06:57 出处:网络
I\'m trying to create a simple script that will convert a string (max 15 chars) to a netbios name (see http://support.microsoft.com/kb/194203) :

I'm trying to create a simple script that will convert a string (max 15 chars) to a netbios name (see http://support.microsoft.com/kb/194203) :

name = sys.argv[1].upper()
converted = ''.join([chr((ord(c)>>4) + ord('A'))+chr((ord(c)&0xF) + ord('A')) for c in name])
print converted

Trying to convert the name : "testing" will return : "4645454646444645454a454f4548" which is co开发者_开发问答rrect. Now depending the length of the name submitted (max 15 chars) we need to pad 4341 until the converted string is 64 long. Example :

./script.py testing:
4645454646444645454a454f4548

But should actually be : 4645454646444645454a454f4548434143414341434143414341434143414341

Anyways to do this easily ?

Thanks !


... + ((16 - len(name)) * '4341')
0

精彩评论

暂无评论...
验证码 换一张
取 消