IP_ADDR=192.168.1.128
printf '%02X' ${IP_ADDR//./ }; echo
Can some one explain how this simple oneliner converts IP_ADDR to hexadecimal format? I am banging my head trying to find some documentation about this behavior.
Shell Parameter Expansion
$ 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 -x 192.168.1.128
C0A80180
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With