Why are you using tac in your command ? This invert the IP digits. As in your example, 12cd34ef = 18.205.52.239, but if I use your command line, the result is 239.52.205.18 (inverted). If I remove the tac, the result is correct. E.g.: 18.205.52.239
(Double checked with https://www.browserling.com/tools/hex-to-ip)
Why not just:
Just create a /bin/hex2ip with:
[ -z $1 ] && echo "Please specify an IP in HEX" && exit
echo " HEX '`echo 00000000$1 | tail -c 9`' IP = `printf "%d." $(echo 00000000$1 | tail -c 9 | sed 's/../0x& /g' | tr ' ' '\n') | sed 's/\.$/\n/'`"
And why not a /bin/ip2hex:
[ -z $1 ] && echo "Please specify an IP" && exit
echo " IP '$1' in HEX = `echo 00000000$(printf "%x" $(echo $1 | sed 's/\./ /g')) | tail -c 9`"
Example:
hex2ip 12cd34ef Will return:
HEX '12cd34ef' IP = 18.205.52.239
ip2hex 18.205.52.239 Will return:
IP '18.205.52.239' in HEX = 12cd34ef
Maxim
Enjoy!