[英]Send a packet of data literally via UDP in Python
I want to my UDP data packet to have literately this information for example: 我想对我的UDP数据包有一定的了解,例如:
data = "83053163021478010102010370020000000000"
I'm using the follow code to send it which works fine(I can see it going out on wireshark): 我正在使用以下代码将其发送正常(我可以看到它在wireshark上发出):
listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
listener.sendto(data, (IP, PORT))
When I look at the data packet in wireshark i want the (wireshark)data packet == data. 当我查看Wireshark中的数据包时,我想要(wireshark)数据包== data。 How do I declare/convert the data type to make this happen.
如何声明/转换数据类型以实现此目的。
I think this should do the trick: 我认为这应该可以解决问题:
import codecs
data = codecs.decode("83053163021478010102010370020000000000", "hex_codec")
Then you can send data
same as you are doing now. 然后,您可以像现在一样发送
data
。
ref: How to create python bytes object from long hex string? 参考: 如何从长十六进制字符串创建python字节对象?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.