IP_ADDR=192.168.1.128
printf '% 02X' $ {IP_ADDR //./}; echo
Can someone explain how this simple oneliner converts IP_ADDR to hexadecimal? I hit my head trying to find documentation of this behavior.
Enhancing Shell Settings
$ IP_ADDR=192.168.1.128 $ echo ${IP_ADDR//./ } 192 168 1 128 $ printf '%02X' 192 168 1 128 ; echo C0A80180
You can simply use gethostip (from syslinux-utils on Debian / Ubuntu):
gethostip
$ gethostip -x 192.168.1.128 C0A80180