1
0
Fork 0
scripts-admin-quickndirty-p.../script_ipv6-proxy.sh

74 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
# Small script for managing ipv6 proxying from a list
# of ipv6 address.
# See some other projects if you need something more elaborate :
# http://priv.nu/projects/ndppd/
# https://github.com/npd6/npd6/
CONFIG_FILE="$( echo "$0" | sed -e 's/.sh$//i' -e 's/$/.conf/' )"
INTERFACE="eth0"
# Fonctions
# affiche le message d'aide
usage() {
cat <<EOF
$0 [ -c config] [ -i interface ] [ -l ]
$0 -h
-c configfile : use this file instead of "$CONFIG_FILE"
-i interface : use this interface instead of "$INTERFACE"
-l : cat the configfile on stdout without actually doing anything.
configfile must simply be filled with one ipv6 address by line.
EOF
}
catconfigfile() {
if [ ! -f "$1" ]; then
return 1
fi
cat "$1" | sed 's/#.*//' | sed -e '/^[[:space:]]*$/d' -e 's/[[:space:]]*//g'
}
# Début du code
# gestion des options de lancement
while getopts c:i:lh f; do
case $f in
'c')
if [ ! -f "$OPTARG" ]; then
echo "ERROR: file '$OPTARG' not found." >&2
exit 1
fi
CONFIG_FILE="$OPTARG"
;;
'i')
INTERFACE="$OPTARG"
;;
'l')
catconfigfile "$CONFIG_FILE"
exit 0
;;
'h')
usage
exit 0
;;
\?)
usage >&2
exit 1
;;
esac
done
#(code inutile, mais que je garde parce qu'on ne sait jamais)
#shift $( expr $OPTIND - 1 )
#DATA="$1"
catconfigfile "$CONFIG_FILE" | while read line; do
ip -6 neigh add proxy "$line" nud permanent dev "$INTERFACE"
done