4 ms·
I wrote this a number of years ago to accomplish same: #!/bin/ksh
by ratsmack 4y ago
I wrote this a number of years ago to accomplish same:
#!/bin/ksh
Die() {
echo Bad IP
exit 1
}
[ $# = 1 ] || Die
[ ${1%%?*.?*.?*.?*} ] && Die
I=$1
until [ ${#I} = 0 ]
do
J=${I#[0-9.]}
[ ${#I} = ${#J} ] && Die
I=$J
done
I=$1.
typeset -ui N=0
while [ $I ]
do
J=${I%%.*}
I=${I#$J.}
[ $((J>>8)) = 0 ] || Die
N=$(( (N<<8) + J ))
done
echo $N
# End