Here are a couple of useful functions for converting IP addresses to their numerical representations in a Bash shell script. Replace “echo 1.2.3.4” with whatever call will output the IP address you are trying to convert.
IP to Decimal:
echo "1.2.3.4" | awk -F '.' '{printf "%dn", ($1 * 2^24) + ($2 * 2^16) + ($3 * 2^8) + $4}'
IP to Hexadecimal:
echo "1.2.3.4" | awk -F '.' '{printf "%xn", ($1 * 2^24) + ($2 * 2^16) + ($3 * 2^8) + $4}'