2012-04-19 17:40:30 -06:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
|
|
|
action=$1; shift
|
|
|
|
|
|
|
|
read n < ip.txt
|
|
|
|
|
2012-06-09 15:55:02 -06:00
|
|
|
if grep -q '/' ip.txt; then
|
|
|
|
IP=$n
|
|
|
|
elif grep -q ipv4 /proc/cmdline; then
|
2012-04-19 17:40:30 -06:00
|
|
|
# IPv4
|
2012-04-24 10:03:14 -06:00
|
|
|
IP="10.0.0.$n/16"
|
2012-04-19 17:40:30 -06:00
|
|
|
else
|
|
|
|
# IPv6
|
|
|
|
l=$(busybox dc 16 o $n p)
|
|
|
|
IP="fd84:b410:3441::$l/64"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ "$action" ] && ip addr $action $IP dev eth0
|
|
|
|
|
|
|
|
if [ "$action" = "add" ]; then
|
|
|
|
fail=fail
|
|
|
|
for i in $(seq 5); do
|
2012-04-24 10:03:14 -06:00
|
|
|
if ip addr | grep -v tentative | grep -Fq $IP; then
|
2012-04-19 17:40:30 -06:00
|
|
|
fail=
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
[ "$fail" ] && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ "$action" = del ] || echo $IP
|