#!/bin/bash # rand.sh - functions for generating public IP addresses function random_ip() { # basing on https://en.wikipedia.org/wiki/Reserved_IP_addresses first=$(echo "$(shuf -i 128-223 -n1; shuf -i 11-126 -n1; shuf -i 1-9 -n1)" | shuf | tail -n1) if [[ $first == 100 ]]; then second=$(echo "$(shuf -i 0-63 -n1; shuf -i 128-254 -n1)" | shuf | tail -n1) _rest elif [[ $first == 169 ]]; then second=$(shuf -i 0-253 -n1) _rest elif [[ $first == 172 ]]; then second=$(echo "$(shuf -i 0-15 -n1; shuf -i 32-254 -n1)" | shuf | tail -n1) _rest elif [[ $first == 192 ]]; then second=$(echo "$(shuf -i 0-167 -n1; shuf -i 169-254 -n1)" | shuf | tail -n1) if [[ $second == 88 ]]; then third=$(echo "$(shuf -i 0-98 -n1; shuf -i 100-254 -n1)" | shuf | tail -n1) else third=$(shuf -i 1-254 -n1) fi fourth=$(shuf -i 1-254 -n1) elif [[ $first == 198 ]]; then second=$(echo "$(shuf -i 0-17 -n1; shuf -i 20-254 -n1)" | shuf | tail -n1) if [[ $second == 51 ]]; then third=$(echo "$(shuf -i 0-99 -n1; shuf -i 101-254 -n1)" | shuf | tail -n1) else third=$(shuf -i 1-254 -n1) fi fourth=$(shuf -i 1-254 -n1) elif [[ $first == 203 ]]; then second=$(shuf -i 0-254 -n1) if [[ $second == 0 ]]; then third=$(echo "$(shuf -i 0-112 -n1; shuf -i 114-254 -n1)" | shuf | tail -n1) else third=$(shuf -i 1-254 -n1) fi fourth=$(shuf -i 1-254 -n1) else second=$(shuf -i 0-254 -n1) _rest fi echo "$first.$second.$third.$fourth" } function _rest() { third=$(shuf -i 0-254 -n1) fourth=$(shuf -i 1-254 -n1) }