mirror of
https://github.com/darkclip/netlist.git
synced 2026-12-07 04:42:33 +08:00
update
This commit is contained in:
1 parent
06fdfac5db
commit
491515d7b0
1 file changed
+47
-25
+47
-25
@@ -46,11 +46,11 @@ get_rnd_hex(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
get_ping_loss(){
|
get_ping_loss(){
|
||||||
if [ $TEST_RUN = 'true' ]; then
|
if [ $TEST_RUN -eq 1 ]; then
|
||||||
echo 100;
|
echo 100;
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
if [ $DRY_RUN = 'true' ]; then
|
if [ $DRY_RUN -eq 1 ]; then
|
||||||
echo 100;
|
echo 100;
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
@@ -93,14 +93,14 @@ generate_ips(){
|
|||||||
num=0;
|
num=0;
|
||||||
while [ $num -lt $max ]; do
|
while [ $num -lt $max ]; do
|
||||||
ip=$($prog);
|
ip=$($prog);
|
||||||
unique=true;
|
unique=1;
|
||||||
for item in $@; do
|
for item in $@; do
|
||||||
if [ "$item" = "$ip" ]; then
|
if [ "$item" = "$ip" ]; then
|
||||||
unique=false;
|
unique=0;
|
||||||
break;
|
break;
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
if [ $unique != 'true' ]; then
|
if [ $unique -eq 0 ]; then
|
||||||
continue;
|
continue;
|
||||||
fi;
|
fi;
|
||||||
set -- $@ $ip;
|
set -- $@ $ip;
|
||||||
@@ -122,7 +122,7 @@ speedtest(){
|
|||||||
rm -f "$result_file";
|
rm -f "$result_file";
|
||||||
echo $ips;
|
echo $ips;
|
||||||
else
|
else
|
||||||
if [ $DRY_RUN != 'true' ]; then
|
if [ $DRY_RUN -eq 0 ]; then
|
||||||
rm -f $exe_file;
|
rm -f $exe_file;
|
||||||
fi;
|
fi;
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -135,7 +135,7 @@ get_ip_cadidates(){
|
|||||||
for item in $(generate_ips $limit $1); do
|
for item in $(generate_ips $limit $1); do
|
||||||
echo "$item" >> "$ip_file";
|
echo "$item" >> "$ip_file";
|
||||||
done;
|
done;
|
||||||
if [ $4 = 'true' ]; then
|
if [ $4 -eq 1 ]; then
|
||||||
result_list=$(speedtest $(archAffix) "$ip_file" $3);
|
result_list=$(speedtest $(archAffix) "$ip_file" $3);
|
||||||
else
|
else
|
||||||
result_list=$(head -$3 "$ip_file" | awk '{print $1":"'$2'}');
|
result_list=$(head -$3 "$ip_file" | awk '{print $1":"'$2'}');
|
||||||
@@ -155,14 +155,14 @@ resolve_ip_addresses(){
|
|||||||
for addr in $addresses; do
|
for addr in $addresses; do
|
||||||
ips=$(getent ahosts $addr | awk '{print $1}');
|
ips=$(getent ahosts $addr | awk '{print $1}');
|
||||||
for ip in $ips; do
|
for ip in $ips; do
|
||||||
unique=true;
|
unique=1;
|
||||||
for item in $@; do
|
for item in $@; do
|
||||||
if [ "$item" = "$ip:$port" ]; then
|
if [ "$item" = "$ip:$port" ]; then
|
||||||
unique=false;
|
unique=0;
|
||||||
break;
|
break;
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
if [ $unique != 'true' ]; then
|
if [ $unique -eq 0 ]; then
|
||||||
continue;
|
continue;
|
||||||
fi;
|
fi;
|
||||||
set -- $@ "$ip:$port";
|
set -- $@ "$ip:$port";
|
||||||
@@ -186,10 +186,10 @@ main(){
|
|||||||
if [ ! "$ENDPOINTS" ]; then
|
if [ ! "$ENDPOINTS" ]; then
|
||||||
if [ $retry -lt $dl_retry_times ]; then
|
if [ $retry -lt $dl_retry_times ]; then
|
||||||
echo "Try to run speed test"
|
echo "Try to run speed test"
|
||||||
cadidates=$(get_ip_cadidates $FAMILY $DEFAULT_PORT $num_cadidates true);
|
cadidates=$(get_ip_cadidates $FAMILY $DEFAULT_PORT $num_cadidates 1);
|
||||||
else
|
else
|
||||||
echo "Use random ip on port $DEFAULT_PORT"
|
echo "Use random ip on port $DEFAULT_PORT"
|
||||||
cadidates=$(get_ip_cadidates $FAMILY $DEFAULT_PORT $num_cadidates false);
|
cadidates=$(get_ip_cadidates $FAMILY $DEFAULT_PORT $num_cadidates 0);
|
||||||
fi;
|
fi;
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
retry=$(($retry + 1));
|
retry=$(($retry + 1));
|
||||||
@@ -204,10 +204,10 @@ main(){
|
|||||||
break;
|
break;
|
||||||
fi;
|
fi;
|
||||||
echo "set $INTERFACE endpoint to $ip_port";
|
echo "set $INTERFACE endpoint to $ip_port";
|
||||||
if [ $TEST_RUN = 'true' ]; then
|
if [ $TEST_RUN -eq 1 ]; then
|
||||||
continue;
|
continue;
|
||||||
fi;
|
fi;
|
||||||
if [ $DRY_RUN = 'true' ]; then
|
if [ $DRY_RUN -eq 1 ]; then
|
||||||
continue;
|
continue;
|
||||||
fi;
|
fi;
|
||||||
if [ ! $INTERFACE ]; then
|
if [ ! $INTERFACE ]; then
|
||||||
@@ -216,11 +216,11 @@ main(){
|
|||||||
wg set $INTERFACE peer $PUB_KEY endpoint $ip_port;
|
wg set $INTERFACE peer $PUB_KEY endpoint $ip_port;
|
||||||
sleep $wait_in_between;
|
sleep $wait_in_between;
|
||||||
done
|
done
|
||||||
if [ $TEST_RUN = 'true' ]; then
|
if [ $TEST_RUN -eq 1 ]; then
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
if [ $DRY_RUN = 'true' ]; then
|
if [ $DRY_RUN -eq 1 ]; then
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
if [ ! $INTERFACE ]; then
|
if [ ! $INTERFACE ]; then
|
||||||
@@ -240,12 +240,30 @@ main(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
pids=$(pgrep -afl $0);
|
|
||||||
if [ $(echo $pids|grep -o $0|wc -l) -gt 1 ]; then
|
|
||||||
echo "Another process is already running.";
|
|
||||||
exit;
|
|
||||||
fi;
|
|
||||||
|
|
||||||
|
already_running(){
|
||||||
|
self=$1;
|
||||||
|
processes=$(pgrep -afl $self);
|
||||||
|
set --;
|
||||||
|
for proc in "$processes"; do
|
||||||
|
unique=1;
|
||||||
|
for item in "$@"; do
|
||||||
|
if [ "$item" = "$proc" ]; then
|
||||||
|
unique=0;
|
||||||
|
break;
|
||||||
|
fi;
|
||||||
|
done;
|
||||||
|
if [ $unique -eq 0 ]; then
|
||||||
|
continue;
|
||||||
|
fi;
|
||||||
|
set -- $@ "$proc";
|
||||||
|
done
|
||||||
|
if [ $(echo "$processes"|wc -l) -eq $(echo "$@"|wc -l) ]; then
|
||||||
|
echo 0;
|
||||||
|
else
|
||||||
|
echo 1;
|
||||||
|
fi
|
||||||
|
};
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
echo "Usage: $0 [OPTIONS]";
|
echo "Usage: $0 [OPTIONS]";
|
||||||
@@ -272,8 +290,8 @@ LOSS_THR=30;
|
|||||||
DEFAULT_PORT=4500;
|
DEFAULT_PORT=4500;
|
||||||
ENDPOINTS='';
|
ENDPOINTS='';
|
||||||
PUB_KEY='bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=';
|
PUB_KEY='bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=';
|
||||||
TEST_RUN=false;
|
TEST_RUN=0;
|
||||||
DRY_RUN=false;
|
DRY_RUN=0;
|
||||||
while getopts ":46i:c:a:l:p:e:k:td" OPT; do
|
while getopts ":46i:c:a:l:p:e:k:td" OPT; do
|
||||||
case $OPT in
|
case $OPT in
|
||||||
4)
|
4)
|
||||||
@@ -304,10 +322,10 @@ while getopts ":46i:c:a:l:p:e:k:td" OPT; do
|
|||||||
PUB_KEY=$OPTARG;
|
PUB_KEY=$OPTARG;
|
||||||
;;
|
;;
|
||||||
t)
|
t)
|
||||||
TEST_RUN=true;
|
TEST_RUN=1;
|
||||||
;;
|
;;
|
||||||
d)
|
d)
|
||||||
DRY_RUN=true;
|
DRY_RUN=1;
|
||||||
;;
|
;;
|
||||||
:)
|
:)
|
||||||
echo "Option -$OPTARG requires an argument.";
|
echo "Option -$OPTARG requires an argument.";
|
||||||
@@ -319,5 +337,9 @@ while getopts ":46i:c:a:l:p:e:k:td" OPT; do
|
|||||||
esac;
|
esac;
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
if [ $(already_running $0) -eq 1 ]; then
|
||||||
|
echo "Another process is already running.";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
main;
|
main;
|
||||||
|
|
||||||
Reference in new issue
Block a user