forked from snakem982/proxypool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalive.sh
214 lines (205 loc) · 6.86 KB
/
alive.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
while getopts ":x:" opt
do
case $opt in
x)
export http_proxy=$OPTARG
export https_proxy=$http_proxy
echo "使用代理 $https_proxy"
;;
?)
echo "未知参数"
exit 1;;
esac
done
jsonQ() {
json=$(cat)
awk -v json="$json" -v json_original="$json" -v key="$1" '
function strLastChar(s) {
return substr(s, length(s), 1)
}
function startWith(s, c) {
start = substr(s, 1, 1)
return start == c
}
function endWith(s, c) {
return strLastChar(s) == c
}
function innerStr(s) {
# 取出括号/引号内的内容
return substr(s, 2, length(s)-2)
}
function strIndex(s, n) {
# 字符串通过下标取值,索引是从1开始的
return substr(s, n, 1)
}
function trim(s) {
sub("^[ \n]*", "", s);
sub("[ \n]*$", "", s);
return s
}
function findValueByKey(s, k) {
if ("\""k"\"" != substr(s, 1, length(k)+2)) {exit 0}
s = trim(s)
start = 0; stop = 0; layer = 0
for (i = 2 + length(k) + 1; i <= length(s); ++i) {
lastChar = substr(s, i - 1, 1)
currChar = substr(s, i, 1)
if (start <= 0) {
if (lastChar == ":") {
start = currChar == " " ? i + 1: i
if (currChar == "{" || currChar == "[") {
layer = 1
}
}
} else {
if (currChar == "{" || currChar == "[") {
++layer
}
if (currChar == "}" || currChar == "]") {
--layer
}
if ((currChar == "," || currChar == "}" || currChar == "]") && layer <= 0) {
stop = currChar == "," ? i : i + 1 + layer
break
}
}
}
if (start <= 0 || stop <= 0 || start > length(s) || stop > length(s) || start >= stop) {
exit 0
} else {
return trim(substr(s, start, stop - start))
}
}
function unquote(s) {
if (startWith(s, "\"")) {
s = substr(s, 2, length(s)-1)
}
if (endWith(s, "\"")) {
s = substr(s, 1, length(s)-1)
}
return s
}
BEGIN{
if (match(key, /^\./) == 0) {exit 0;}
sub(/\][ ]*\[/,"].[", key)
split(key, ks, ".")
if (length(ks) == 1) {print json; exit 0}
for (j = 2; j <= length(ks); j++) {
k = ks[j]
if (startWith(k, "[") && endWith(k, "]") == 1) { # [n]
idx = innerStr(k)
currentIdx = -1
# 找匹配对
pairs = ""
json = trim(json)
if (startWith(json, "[") == 0) {
exit 0
}
start = 2
cursor = 2
for (; cursor <= length(json); cursor++) {
current = strIndex(json, cursor)
if (current == " " || current == "\n") {continue}
# 忽略空白
if (current == "[" || current == "{") {
if (length(pairs) == 0) {start = cursor}
pairs = pairs""current
}
if (current == "]" || current == "}") {
if ((strLastChar(pairs) == "[" && current == "]") || (strLastChar(pairs) == "{" && current == "}")) {
pairs = substr(pairs, 1, length(pairs)-1)
# 删掉最后一个字符
if (pairs == "") {
# 匹配到了所有的左括号
currentIdx++
if (currentIdx == idx) {
json = substr(json, start, cursor-start+1)
break
}
}
} else {
pairs = pairs""current
}
}
}
} else {
# 到这里,就只能是{"key": "value"}或{"key":{}}或{"key":[{}]}
pairs = ""
json = trim(json)
if (startWith(json, "[")) {exit 0}
#if (!startWith(json, "\"") || !startWith(json, "{")) {json="\""json}
# 找匹配的键
start = 2
cursor = 2
noMatch = 0
for (; cursor <= length(json); cursor++) {
current = strIndex(json, cursor)
if (current == " " || current == "\n" || current == ",") {continue}
# 忽略空白和逗号
if (substr(json, cursor, length(k)+2) == "\""k"\"") {
json = findValueByKey(substr(json, cursor, length(json)-cursor+1), k)
break
} else {
noMatch = 1
}
if (noMatch) {
pos = match(substr(json, cursor+1, length(json)-cursor), /[^(\\")]"/)
ck = substr(substr(json, cursor+1, length(json)-cursor), 1, pos)
t = findValueByKey(substr(json, cursor, length(json)-cursor+1), ck)
tLen = length(t)
sub(/\\/, "\\\\", t)
pos = match(substr(json, cursor+1, length(json)-cursor), t)
if (pos != 0) {
cursor = cursor + pos + tLen
}
noMatch = 0
continue
}
}
}
}
if (json_original == json) { print;exit 0 }
print unquote(json)
}'
}
month=2592000
timestamp=$(date +%s)
lastMonth=$(( timestamp-month ))
function isUpdated()
{
t1=`gdate -d "$1" +%s`
if [ $t1 -gt $lastMonth ]
then
return 0
else
return 1
fi
}
rm -rf result.log
i=1
data=$(cat nodelist.txt)
for url in $data; do
if [[ $url == https://raw.githubusercontent.com* ]]; then
i=$[$i+1]
code=$(curl -o /dev/null -k -s -w %{http_code} $url)
if [ $code -ne 404 ]
then
arr=(`echo $url | tr '/' ' '`)
repository=${arr[2]}%2F${arr[3]}
response=$(curl -s https://github.com/search?q=$repository&type=repositories)
response=$(echo "$response" | jsonQ ".payload.results.[0].repo.repository.updated_at")
response=${response: 0: 19}
response=${response/T/' '}
if isUpdated $response ; then
echo $url >> result.log
fi
fi
ix=`expr $i % 8`
if [ $ix -eq 0 ]
then
echo stop
sleep 120
fi
fi
done