Add increment IPv6

This commit is contained in:
Tristan Le Chanony 2019-11-08 08:15:15 +01:00
parent ba85193af1
commit 348c4b1151
2 changed files with 65 additions and 0 deletions

64
increment_ip.sh Normal file
View File

@ -0,0 +1,64 @@
#!/bin/bash
## author : Dryusdan
## date : 30/09/2019
## description : An incremental IP
## usage : ./increment_ip.sh
## Bash strict mode ####################################
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
## Bash color ##########################################
# Set colors
RED='\033[0;31m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
BLUE='\033[00;34m'
PURPLE='\033[00;35m'
CYAN='\033[00;36m'
LIGHTGRAY='\033[00;37m'
LRED='\033[01;31m'
LGREEN='\033[01;32m'
LYELLOW='\033[01;33m'
LBLUE='\033[01;34m'
LPURPLE='\033[01;35m'
LCYAN='\033[01;36m'
WHITE='\033[01;37m'
NC='\033[0m' # No Color
## Logs ################################################
readonly SCRIPTNAME="$(basename "$0")"
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
########################################################
info "start ${SCRIPTNAME}"
## Define variables ####################################
LAST_DIGIT=$(cat last_digit.txt)
LAST_DIGIT_HEXA=$((16#${LAST_DIGIT}))
RANGE="2a01:4f8:161:2269:8000:c01d:c01a:"
########################################################
## Starting script #####################################
info "generating new IP"
for i in $(seq ${LAST_DIGIT_HEXA} $((16#ffff)));
do
NEW_IP=$(printf "${RANGE}%.4x\n" $i)
LAST_DIGIT_NEW_IP=$(printf '%x\n' $i)
break;
done
info "Setting new IP"
ip -6 addr add ${NEW_IP}/65 dev eth0
info "Remove last IP"
ip -6 addr del ${RANGE}:${LAST_DIGIT}/65 dev eth0
echo ${LAST_DIGIT_NEW_IP} > last_digit.txt
info "Ending script"
#######################################################

1
last_digit.txt Normal file
View File

@ -0,0 +1 @@
cb06