This commit is contained in:
darkclip committed 2023-12-31 19:53:49 +08:00
1 parent 7a5cf99d40
commit fcaabeaf50
1 file changed
+21 -6
+21 -6
View File
@@ -39,6 +39,10 @@ get_rnd_hex(){
}; };
get_ping_loss(){ get_ping_loss(){
if [ $TEST_RUN == 'true' ]; then
echo 100;
exit;
fi;
if [ $DRY_RUN == 'true' ]; then if [ $DRY_RUN == 'true' ]; then
echo 100; echo 100;
exit; exit;
@@ -166,7 +170,10 @@ main(){
if [ $loss -lt $LOSS_THR ]; then if [ $loss -lt $LOSS_THR ]; then
break; break;
fi; fi;
echo "changing $INTERFACE endpoint to $cfip"; echo "set $INTERFACE endpoint to $cfip";
if [ $TEST_RUN == 'true' ]; then
continue;
fi;
if [ $DRY_RUN == 'true' ]; then if [ $DRY_RUN == 'true' ]; then
continue; continue;
fi; fi;
@@ -176,15 +183,18 @@ main(){
wg set $INTERFACE peer 'bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=' endpoint $cfip; wg set $INTERFACE peer 'bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=' endpoint $cfip;
sleep $wait_in_between; sleep $wait_in_between;
done done
if [ $TEST_RUN == 'true' ]; then
exit;
fi;
done; done;
if [ $DRY_RUN = 'true' ]; then if [ $DRY_RUN = 'true' ]; then
exit 0; exit;
fi; fi;
if [ ! $INTERFACE ]; then if [ ! $INTERFACE ]; then
exit 0; exit;
fi; fi;
if [ ! $CONFIG ]; then if [ ! $CONFIG ]; then
exit 0; exit;
fi; fi;
endpoint=$(wg show $INTERFACE endpoints | awk '{print $2}'); endpoint=$(wg show $INTERFACE endpoints | awk '{print $2}');
if [ "$(uname -i)" == 'pfSense' ]; then if [ "$(uname -i)" == 'pfSense' ]; then
@@ -205,7 +215,7 @@ fi;
usage(){ usage(){
echo "Usage: $0 [-4] [-6] [-i <INTERFACE>] [-c <CONFIG>] [-a <ADDRESS>] [-l <LOSS>] [-p <PORT>] [-d]"; echo "Usage: $0 [-4] [-6] [-i <INTERFACE>] [-c <CONFIG>] [-a <ADDRESS>] [-l <LOSS>] [-p <PORT>] [-t] [-d]";
echo "Options:" echo "Options:"
echo " -4 IPv4" echo " -4 IPv4"
echo " -6 IPv6" echo " -6 IPv6"
@@ -214,6 +224,7 @@ usage(){
echo " -a ADDRESS Watch address" echo " -a ADDRESS Watch address"
echo " -l LOSS Loss threshold" echo " -l LOSS Loss threshold"
echo " -p PORT Default port" echo " -p PORT Default port"
echo " -t Speed test only"
echo " -d Dry run" echo " -d Dry run"
} }
@@ -223,8 +234,9 @@ CONFIG='';
WATCH_ADD='1.1.1.1'; WATCH_ADD='1.1.1.1';
LOSS_THR=40; LOSS_THR=40;
DEFAULT_PORT=4500; DEFAULT_PORT=4500;
TEST_RUN=false;
DRY_RUN=false; DRY_RUN=false;
while getopts ":h46i:c:a:l:p:d" opt; do while getopts ":h46i:c:a:l:p:td" opt; do
case $opt in case $opt in
h) h)
usage; usage;
@@ -250,6 +262,9 @@ while getopts ":h46i:c:a:l:p:d" opt; do
p) p)
DEFAULT_PORT=$OPTARG; DEFAULT_PORT=$OPTARG;
;; ;;
t)
TEST_RUN=true;
;;
d) d)
DRY_RUN=true; DRY_RUN=true;
;; ;;