diff options
author | Aaron LI <aly@aaronly.me> | 2020-06-20 19:03:23 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2020-06-20 19:03:23 +0800 |
commit | 5e85866a81221b73407740b255b565481ceb7494 (patch) | |
tree | fd9a3f62a3155c132702fe47f9e2e6c7a4288004 | |
parent | d388c0d2dfeb66a3d459b1481dd950ee6559d668 (diff) | |
download | dotfiles-5e85866a81221b73407740b255b565481ceb7494.tar.bz2 |
zsh: Add ip2hex() and hex2ip() functions
-rw-r--r-- | _zshrc | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -221,6 +221,15 @@ ccdef() { ${1:-cc} $@[2,-1] -dM -E - </dev/null } +## Convert IP between dotted-decimal and hexdecimal notation +# Credit: https://stackoverflow.com/a/6149254 +ip2hex() { + printf '%02X' $(echo "$1" | sed 's/\./ /g') +} +hex2ip() { + printf '%d.%d.%d.%d' $(echo "${1#0[xX]}" | sed 's/\(..\)/0x\1 /g') +} + # # Terminal settings # |