-
Notifications
You must be signed in to change notification settings - Fork 0
/
nat_ubuntu.sh
103 lines (85 loc) · 1.84 KB
/
nat_ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
export PATH=$PATH:/usr/local/bin/:/usr/bin/
daemon1=nat123a
daemon2=nat123b
daemon=nat123
function kill_daemon {
killall -u $(whoami) -e mono
sleep 0.3
screen -X -S $daemon1 quit 2>&1 1>/dev/null
sleep 0.3
screen -X -S $daemon2 quit 2>&1 1>/dev/null
sleep 0.5
screen -X -S $daemon quit 2>&1 1>/dev/null
sleep 0.3
screen -wipe 2>&1 1>/dev/null
}
echo '#!/bin/bash
export path=$path:/usr/local/bin/:/usr/bin/
c9ssh_root=/usr/local/c9ssh/
sleep_interval=60
daemon=nat123
daemon1=nat123a
daemon2=nat123b
function online {
echo -e "GET http://baidu.com HTTP/1.0\n\n" | nc baidu.com 80 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "true"
else
echo "false"
fi
}
function kill_daemon1 {
echo "kill_daemon1"
screen -X -S $daemon1 quit 2>&1 1>/dev/null
}
function kill_daemon2 {
echo "kill_daemon2"
killall -u $(whoami) -e mono
screen -X -S $daemon2 quit 2>&1 1>/dev/null
}
function remote_daemon1 {
kill_daemon1
echo "start remote_daemon1"
screen -dmS $daemon1 /usr/bin/mono $c9ssh_root"nat123linux.sh" autologin stone55 ft123456!
}
function remote_daemon2 {
kill_daemon2
echo "start remote_daemon2"
screen -dmS $daemon2 /usr/bin/mono $c9ssh_root"nat123linux.sh" service
}
function nat_daemon {
sync="false"
newstatus=$(online)
status=$newstatus
while true; do
if [ "$sync" == "false" ]; then
if [ "$status" == "true" ]; then
echo "start remote_daemon"
remote_daemon1
sleep 15
remote_daemon2
sync="true"
status=$newstatus
else
kill_daemon1
kill_daemon2
sync="true"
status=$newstatus
fi
else
echo "sleep "$sleep_interval
sleep $sleep_interval
newstatus=$(online)
if [ ! "$newstatus" == "$status" ]; then
sync="false"
status=$newstatus
fi
fi
done
}
nat_daemon
' > /var/tmp/remote.sh
remote_sh="/var/tmp/remote.sh"
kill_daemon
screen -dm -S $daemon /bin/bash $remote_sh