0

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.

2
  • Do you mean that you want to convert the hexadecimal values in the data into raw binary? Otherwise I don't understand the question Commented Oct 30, 2014 at 18:55
  • data is a hex string represented as ascii string. I want listener.sendto(data, (IP, PORT)) to send data as the literal hex bytes that the data string equals Commented Oct 30, 2014 at 19:05

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

hcs, Thank you so much this works perfect and was exactly what I was trying to do. You have no idea how thankful I am for your answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.