如何使用asn1tools解码asn1十六进制值 [英] How decode asn1 hex value using asn1tools
本文介绍了如何使用asn1tools解码asn1十六进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Python解码以下ASN1消息
I'm trying to decode the following ASN1 message using Python
b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x02\x89G\x11\x00\x1a\x01\x00\x10\x00\x80\x00\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x02\x98c\xc7h\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
这是我的代码:
import asn1tools
import socket
import sys
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_address = ('239.118.122.97', 8947)
#server_address = ('localhost', 8947)
#server_address = ('192.168.1.63', 8948)
#server_address = ('0.0.0.0', 8947)
print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)
while True:
print('\nwaiting to receive message')
data, address = sock.recvfrom(8947)
print('\nreceived {} bytes from {}'.format(
len(data), address))
print(data)
foo = asn1tools.compile_files(data,'uper')
我收到以下错误:
Traceback (most recent call last):
File "udp.py", line 21, in <module>
foo = asn1tools.compile_files(data,'uper')
File "/usr/local/lib/python3.6/dist-packages/asn1tools/compiler.py", line 376, in compile_files
return compile_dict(parse_files(filenames, encoding),
File "/usr/local/lib/python3.6/dist-packages/asn1tools/parser.py", line 1877, in parse_files
with open(filename, 'r', encoding=encoding, errors='replace') as fin:
OSError: [Errno 9] Bad file descriptor
我希望收到JSON格式的消息.
I expect a JSON format message.
推荐答案
快速浏览文档会发现compile_files用于编译ASN规范(看起来像是使用文件名).您似乎想在编码数据上使用它.
A quick look at the documentation indicates that compile_files is for compiling the ASN specification (looks like it takes a file name). You appear to be trying to use it on the encoded data.
这篇关于如何使用asn1tools解码asn1十六进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文