diff options
author | Aaron LI <aly@aaronly.me> | 2022-01-15 10:53:33 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2023-06-13 10:01:03 +0800 |
commit | 8e94814d0708d312293e94e6a35f4b5ad555c263 (patch) | |
tree | f546aa458edeaae4ef23386411c090a422a45195 | |
parent | 384b1ecc194d31e2e35d361a7715d32047c32537 (diff) | |
download | dotfiles-8e94814d0708d312293e94e6a35f4b5ad555c263.tar.bz2 |
zsh: Add ip2dec() and dec2ip() functions
-rw-r--r-- | _zshrc | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -230,6 +230,16 @@ hex2ip() { printf '%d.%d.%d.%d' $(echo "${1#0[xX]}" | sed 's/\(..\)/0x\1 /g') } +## Convert IP between dotted-decimal and decimal notation +# Credit: https://stackoverflow.com/a/24136051 +ip2dec() { + echo "$1" | awk 'BEGIN { RS = "." } { d = d * 256 + $1 } END { print d }' +} +# Credit: https://stackoverflow.com/a/31281331 +dec2ip() { + printf '%d.%d.%d.%d' $(echo "obase=256; $1" | bc) +} + # # Terminal settings # |