citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

proquint-ip (419B)


      1 #!/usr/bin/env bash
      2 
      3 usage () {
      4     printf "proquint-ip <ip-address or proquint>"
      5 }
      6 
      7 if [ -z $1 ]
      8 then usage
      9     exit 1
     10 fi
     11 
     12 input="$1"
     13 is_ip=0
     14 
     15 if [[ $1 =~ ^[0-9] ]]
     16 then
     17     is_ip=1
     18     input=$(<<<"$1" sed 's,\., ,g' | xargs printf 'x%02x%02x%02x%02x\n')
     19 fi
     20 
     21 output=$(proquint "$input")
     22 
     23 if [[ is_ip -eq 0 ]]
     24 then
     25     <<<"$output" sed 's,^x,,;s,.\{2\},0x& ,g' | xargs printf '%d.%d.%d.%d\n'
     26 else
     27     echo "$output"
     28 fi