Created
July 27, 2018 14:03
-
-
Save darkshade9/afd50ff350f6e6d42643acb179cf7b1e to your computer and use it in GitHub Desktop.
Finds an available IP address by scanning current records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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