开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜