Bash script for converting IP Addr string to Hexadecimal format
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
精彩评论