hex dec ip
#!/bin/bash dec2ip () { local ip dec=$@ for e in {3..0} do ((octet = dec / (256 ** e) )) ((dec -= octet * 256 ** e)) ip+=$delim$octet delim=. done printf '%s\n' "$ip" } dec2ip "$@"
#!/bin/bash ip2dec () { local a b c d ip=$@ IFS=. read -r a b c d <<< "$ip" printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))" } ip2dec "$@"
dec2ip () { local v=$1 local i1=$((v>>24&255)) local i2=$((v>>16&255)) local i3=$((v>>8&255)) local i4=$((v&255)) printf '%d.%d.%d.%d\n' $i1 $i2 $i3 $i4 }
tohex
echo -n 10.0.14.5 | hexdump -e '/1 "%02x"';
ip2hex
gethostip -x 10.0.14.5
hex2ip
hextoip() { hex=$1; printf "%d." 0x${hex:0:2}; printf "%d." 0x${hex:2:2}; printf "%d." 0x${hex:4:2}; printf "%d" 0x${hex:6:2}; }
none