I find it difficult to change hex to int / char (char is preferred). Through the website; http://home2.paulschou.net/tools/xlate/ I enter the hexadecimal code C0A80026 in the hexadecimal field, in the DEC / CHAR field it correctly displays the IP address that I expected from it to contain.
This data is extracted from an external database, and I do not know how it is stored, so all I have to work with is the hexadecimal string itself.
I tried using the binascii.unhexlify
function to see if I can decode it, but I'm afraid that I may not have enough understanding of the hex to evaluate what I'm doing.
When trying to print only using the int () method, the required results were also not obtained. I need to somehow convert from this hexadecimal string (or one like that) to the original IP address.
UPDATE: for anyone facing this in the future, I slightly modified the answer below to provide an accurate printout as IP using <
dec_output = str(int(hex_input[0:2], 16)) + "." + str(int(hex_input[2:4], 16)) + "." + str(int(hex_input[4:6], 16)) + "." + str(int(hex_input[6:8], 16))
source share