I'm appending some hex bytes into a packet = [] and I want to return these hex bytes in the form of 0x__ as hex data.
packet.append("2a")
packet.append("19")
packet.append("00")
packet.append("00")
packHex = []
for i in packet:
packHex.append("0x"+i) #this is wrong
return packHex
How do I go about converting ('2a', '19', '00', '00') in packet to get (0x2a, 0x19, 0x0, 0x0) in packHex? I need real hex data, not strings that look like hex data.
I'm assembling a packet to be sent over pcap, pcap_sendpacket(fp,packet,len(data)) where packet should be a hexadecimal list or tuple for me, maybe it can be done in decimal, haven't tried, I prefer hex. Thank you for your answer.
packetPcap[:len(data)] = packHex
Solved:
for i in packet: packHex.append(int(i,16))
If output in hex needed, this command can be used:
print ",".join(map(hex, packHex))