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.

Nimjox
  • 1,271
  • 5
  • 18
  • 33
  • Do you mean that you want to convert the hexadecimal values in the data into raw binary? Otherwise I don't understand the question – hcs Oct 30 '14 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 – Nimjox Oct 30 '14 at 19:05

1 Answers1

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?

Community
  • 1
  • 1
hcs
  • 1,514
  • 9
  • 14
  • 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! – Nimjox Oct 30 '14 at 19:19