Skip to content

Instantly share code, notes, and snippets.

@darkshade9
Created July 27, 2018 14:03
Show Gist options
  • Select an option

  • Save darkshade9/afd50ff350f6e6d42643acb179cf7b1e to your computer and use it in GitHub Desktop.

Select an option

Save darkshade9/afd50ff350f6e6d42643acb179cf7b1e to your computer and use it in GitHub Desktop.
Finds an available IP address by scanning current records
#!/bin/bash
firstOctetinRange=9
secondOctet=253
foundIP=0
for i in $ovpn_ip
do
ovpn_octet=$(echo $i | cut -f 4 -d .)
if [[ 10.${secondOctet}.0.${ovpn_octet} = 10.${secondOctet}.0.${firstOctetinRange} && $foundIP = 0 ]]; then
echo "$i is taken, trying the next IP"
firstOctetinRange=$(($firstOctetinRange + 1))
if [[ ${firstOctetinRange} -gt 254 ]]; then
echo "ERROR: Octet has reached the end of the network (253)"
exit 1
fi
if [[ ${ovpn_ip[*]} != 10.${secondOctet}.0.${firstOctetinRange} ]]; then
echo "Using 10.${secondOctet}.0.${firstOctetinRange}"
newOpenVPNIP="10.${secondOctet}.0.${firstOctetinRange}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment