dot

packages and services management
Log | Files | Refs | README

commit cc09bb2507cc4b2ec02c0360b2675e3a1fb455c5
parent a1318e4e8c8c18f82fe11946fbbf5772898cf8d2
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Fri, 30 Jun 2017 18:23:46 +0200

thanks nikkita ^)^

Diffstat:
Abin/ipconv | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/bin/ipconv b/bin/ipconv @@ -0,0 +1,32 @@ + +if [ -z "$1" ] || [ $# -ne 1 ] +then + exit 1 + +elif [ -z "$(printf %s "$1" | tr -d 0-9)" ] +then + int=$1 ip= + + while [ "$int" -gt 0 ] + do + byte=$((int & 255)) + int=$((int / 256)) + [ -z "$ip" ] && ip="$byte" || ip="$byte.$ip" + done + + printf '%s\n' "$ip" + +elif [ -z "$(printf %s "$1" | tr -d 0-9.)" ] +then + ip=$1 int=0 IFS=. + + for byte in $ip + do + int=$((int * 256 + byte)) + done + + printf '%s\n' "$int" + +else + exit 1 +fi