简体   繁体   中英

Send a packet of data literally via UDP in Python

I want to my UDP data packet to have literately this information for example:

data = "83053163021478010102010370020000000000"

I'm using the follow code to send it which works fine(I can see it going out on 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. 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.

ref: How to create python bytes object from long hex string?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM