forked from jinwyp/one_click_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetflix_check.sh
executable file
·468 lines (321 loc) · 12.7 KB
/
netflix_check.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#!/bin/bash
Font_Black="\033[30m"
Font_Red="\033[31m"
Font_Green="\033[32m"
Font_Yellow="\033[33m"
Font_Blue="\033[34m"
Font_Purple="\033[35m"
Font_SkyBlue="\033[36m"
Font_White="\033[37m"
Font_Suffix="\033[0m"
# fonts color
red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
yellow(){
echo -e "\033[33m\033[01m$1\033[0m"
}
blue(){
echo -e "\033[34m\033[01m$1\033[0m"
}
bold(){
echo -e "\033[1m\033[01m$1\033[0m"
}
UA_Browser="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36";
configWARPPortFilePath="${HOME}/wireguard/warp-port"
configWARPPortLocalServerPort="40000"
warpPortInput="${1:-40000}"
isAutoRefreshWarp=""
function testWARPEnabled(){
if [[ -f "${configWARPPortFilePath}" ]]; then
configWARPPortLocalServerPort="$(cat ${configWARPPortFilePath})"
yellow "检测到本机已安装 WARP Sock5, 端口号 ${configWARPPortLocalServerPort}"
echo
fi
if [[ "$isAutoRefreshWarp" == "true" ]]; then
warpPortInput="${configWARPPortLocalServerPort}"
else
read -p "请输入WARP Sock5 端口号? 直接回车默认${configWARPPortLocalServerPort}, 请输入纯数字:" warpPortInput
warpPortInput=${warpPortInput:-$configWARPPortLocalServerPort}
fi
echo
}
isIPV6Enabled="false"
function testIPV6Enabled(){
cmdCatIpv6=$(cat /sys/module/ipv6/parameters/disable)
isIPV6Enabled="false"
if [[ ${cmdCatIpv6} == "0" ]]; then
isIPV6Enabled="true"
fi
cmd1SysCtlIpv6=$(sysctl -a 2>/dev/null | grep net.ipv6.conf.all.disable_ipv6 | awk -F " " '{print $3}' )
cmd2SysCtlIpv6=$(sysctl -a 2>/dev/null | grep net.ipv6.conf.default.disable_ipv6 | awk -F " " '{print $3}' )
if [[ ${cmd1SysCtlIpv6} == "0" && ${cmd2SysCtlIpv6} == "0" ]]; then
isIPV6Enabled="true"
fi
}
function testNetflixAll(){
curlCommand="curl --connect-timeout 10 -sL"
curlInfo="IPv4"
if [[ $1 == "ipv4" ]]; then
bold " 开始测试本机的IPv4 解锁 Netflix 情况"
curlCommand="${curlCommand} -4"
curlInfo="IPv4"
elif [[ $1 == "ipv4warp" ]]; then
read -p "是否测试本机 IPv4 WARP Sock5 代理? 直接回车默认不测试 请输入[y/N]:" isIpv4WARPContinueInput
isIpv4WARPContinueInput=${isIpv4WARPContinueInput:-n}
if [[ ${isIpv4WARPContinueInput} == [Nn] ]]; then
red " 已退出本机 IPv4 WARP Sock5 代理测试"
echo
return
else
testWARPEnabled
bold " 开始测试本机的IPv4 通过CloudFlare WARP 解锁 Netflix 情况"
curlCommand="${curlCommand} -x socks5h://127.0.0.1:${warpPortInput}"
curlInfo="IPv4 CloudFlare WARP"
fi
elif [[ $1 == "ipv6" ]]; then
if [[ "${isIPV6Enabled}" == "false" ]]; then
red " 本机IPv6 没有开启 是否继续测试IPv6 "
read -p "是否继续测试IPv6? 直接回车默认不继续测试 请输入[y/N]:" isIpv6ContinueInput
isIpv6ContinueInput=${isIpv6ContinueInput:-n}
if [[ ${isIpv6ContinueInput} == [Nn] ]]; then
red " 已退出 本机IPv6 测试 "
echo
return
else
echo
bold " 开始测试本机的IPv6 解锁 Netflix 情况"
curlCommand="${curlCommand} -6"
curlInfo="IPv6"
fi
else
bold " 开始测试本机的IPv6 解锁 Netflix 情况"
curlCommand="${curlCommand} -6"
curlInfo="IPv6"
fi
elif [[ $1 == "ipv6warp" ]]; then
bold " 开始测试本机的IPv6 通过CloudFlare WARP 解锁 Netflix 情况"
curlCommand="${curlCommand} -6"
curlInfo="IPv6 CloudFlare WARP"
else
red " 没有选择要进行的测试 已退出! "
return
fi
# curl 参数说明
# --connect-timeout <seconds> Maximum time allowed for connection
# -4, --ipv4 Resolve names to IPv4 addresses
# -s, --silent Silent mode
# -S, --show-error Show error even when -s is used
# -L, --location Follow redirects
# -i, --include Include protocol response headers in the output
# -f, --fail Fail silently (no output at all) on HTTP errors
testNetflixOneMethod "${curlCommand}" "${curlInfo}"
echo
}
function testNetflixOneMethod(){
# https://stackoverflow.com/questions/3869072/test-for-non-zero-length-string-in-bash-n-var-or-var
if [[ -n "$1" ]]; then
netflixLinkIndex="https://www.netflix.com/"
netflixLinkOwn="https://www.netflix.com/title/80018499"
# green " Test Url: $1 -S ${netflixLinkIndex}"
resultIndex=$($1 -S ${netflixLinkIndex} 2>&1)
if [[ "${resultIndex}" == "curl"* ]];then
red " 网络错误 无法打开 Netflix 网站"
return
fi
if [[ -z "${resultIndex}" ]];then
resultIndex2=$($1 -S ${netflixLinkIndex} 2>&1)
if [[ -z "${resultIndex2}" ]];then
red " 已被 Netflix 屏蔽, 403 访问错误 "
return
fi
fi
if [ "${resultIndex}" == "Not Available" ];then
red " Netflix 不提供此地区服务 "
if [[ "$isAutoRefreshWarp" == "true" ]]; then
echo
else
return
fi
fi
# green " Test Url: $1 -S ${netflixLinkOwn}"
resultOwn=$($1 -S ${netflixLinkIndex} 2>&1)
if [[ "${resultOwn}" == *"page-404"* ]] || [[ "${resultOwn}" == *"NSEZ-403"* ]];then
red " 本机 $2 不能播放 Netflix 任何剧集"
return
fi
# green " Test Url: $1 -fi https://www.netflix.com/title/80018499 2>&1 | sed -n '8p'"
resultRegion=`tr [:lower:] [:upper:] <<< $($1 -fi "https://www.netflix.com/title/80018499" 2>&1 | sed -n '8p' | awk '{print $2}' | cut -d '/' -f4 | cut -d '-' -f1)`
netflixRegion="${resultRegion}"
# echo "x-robots-tag: ${netflixRegion}"
if [[ "${resultRegion}" == *"INDEX"* ]] || [[ "${resultRegion}" == *"index"* ]];then
netflixRegion="US"
fi
result1=$($1 -S "https://www.netflix.com/title/70143836" 2>&1)
result2=$($1 -S "https://www.netflix.com/title/80027042" 2>&1)
result3=$($1 -S "https://www.netflix.com/title/70140425" 2>&1)
result4=$($1 -S "https://www.netflix.com/title/70283261" 2>&1)
result5=$($1 -S "https://www.netflix.com/title/70143860" 2>&1)
result6=$($1 -S "https://www.netflix.com/title/70202589" 2>&1)
if [[ "$result1" == *"page-404"* ]] && [[ "$result2" == *"page-404"* ]] && [[ "$result3" == *"page-404"* ]] && [[ "$result4" == *"page-404"* ]] && [[ "$result5" == *"page-404"* ]] && [[ "$result6" == *"page-404"* ]]; then
yellow " 本机 $2 仅解锁 Netflix 自制剧, 无法播放非自制剧. 区域: ${netflixRegion}"
if [[ $2 == "IPv4 CloudFlare WARP Refresh" ]]; then
echo
green " 重启Warp 用于刷新能解锁IP, $2"
warp_restart
sleep 2
autoRefreshWarpIP
fi
return
fi
green " 恭喜 本机 $2 解锁 Netflix 全部剧集 包括非自制剧. 区域: ${netflixRegion} "
return
else
red " 要进行的测试 Url为空! "
fi
}
function warp_restart(){
if [ -f /etc/wireguard/wgcf.conf ]; then
systemctl restart wg-quick@wgcf
sleep 2
fi
if [ -f /usr/bin/warp-cli ]; then
# systemctl restart warp-svc
# sleep 3
warp-cli --accept-tos delete
sleep 2
warp-cli --accept-tos register
sleep 2
warp-cli --accept-tos connect
sleep 2
fi
green " 已经完成 重启Warp "
}
counter=1
function autoRefreshWarpIPStart(){
if [[ "$isAutoRefreshWarp" == "true" ]]; then
testWARPEnabled
autoRefreshWarpIP
fi
}
function autoRefreshWarpIP(){
# https://stackoverflow.com/questions/13638670/adding-counter-in-shell-script
if [[ "$isAutoRefreshWarp" == "true" ]]; then
echo
time=$(date "+%Y-%m-%d %H:%M:%S")
green " $time 开始自动刷新 WARP IP, 默认尝试20次 此次为第${counter}次"
echo
curlCommand="curl --connect-timeout 10 -sL"
curlInfo="IPv4 CloudFlare WARP Refresh"
if [ -f /usr/bin/warp-cli ]; then
bold " 开始测试本机的IPv4 通过CloudFlare WARP sock5 解锁 Netflix 情况"
curlCommand="${curlCommand} -x socks5h://127.0.0.1:${warpPortInput}"
else
bold " 开始测试本机的IPv6 通过CloudFlare WARP 解锁 Netflix 情况"
curlCommand="${curlCommand} -6"
fi
if [[ "$counter" -gt 20 ]]; then
exit 1
else
counter=$((counter+1))
testNetflixOneMethod "${curlCommand}" "${curlInfo}"
fi
echo
fi
}
function testYoutubeAll(){
# curlCommand="curl --connect-timeout 10 -s --user-agent ${UA_Browser}"
curlCommand="curl --connect-timeout 10 -s"
curlInfo="IPv4"
if [[ $1 == "ipv4" ]]; then
bold " 开始测试本机的IPv4 解锁 Youtube Premium 情况"
curlCommand="${curlCommand} -4"
curlInfo="IPv4"
elif [[ $1 == "ipv4warp" ]]; then
if [[ ${isIpv4WARPContinueInput} == [Nn] ]]; then
red " 已退出本机 IPv4 WARP Sock5 代理测试"
echo
return
else
bold " 开始测试本机的IPv4 通过CloudFlare WARP 解锁 Youtube Premium 情况"
curlCommand="${curlCommand} -x socks5h://127.0.0.1:${warpPortInput}"
curlInfo="IPv4 CloudFlare WARP"
fi
elif [[ $1 == "ipv6" ]]; then
if [[ "${isIPV6Enabled}"=="false" ]]; then
if [[ ${isIpv6ContinueInput} == [Nn] ]]; then
red " 已退出 本机IPv6 测试 "
echo
return
else
bold " 开始测试本机的IPv6 解锁 Youtube Premium 情况"
curlCommand="${curlCommand} -6"
curlInfo="IPv6"
fi
else
bold " 开始测试本机的IPv6 解锁 Youtube Premium 情况"
curlCommand="${curlCommand} -6"
curlInfo="IPv6"
fi
elif [[ $1 == "ipv6warp" ]]; then
bold " 开始测试本机的IPv6 通过CloudFlare WARP 解锁 Youtube Premium 情况"
curlCommand="${curlCommand} -6"
curlInfo="IPv6 CloudFlare WARP"
else
red " 没有选择要进行的测试 已退出! "
return
fi
# curl 参数说明
# --connect-timeout <seconds> Maximum time allowed for connection
# -4, --ipv4 Resolve names to IPv4 addresses
# -s, --silent Silent mode
# -S, --show-error Show error even when -s is used
# -L, --location Follow redirects
testYoutubeOneMethod "${curlCommand}" "${curlInfo}"
echo
}
function testYoutubeOneMethod(){
if [[ -n "$1" ]]; then
youtubeLinkRed="https://www.youtube.com/red"
# green " Test Url: $1 ${youtubeLinkRed}"
resultYoutubeIndex=$($1 -S ${youtubeLinkRed} 2>&1)
if [[ "${resultYoutubeIndex}" == "curl"* ]];then
red " 网络错误 无法打开 YouTube 网站"
return
fi
resultYoutube=$($1 ${youtubeLinkRed} | sed 's/,/\n/g' | grep countryCode | cut -d '"' -f4)
if [ ! -n "${resultYoutube}" ]; then
yellow " YouTube 角标不显示 可能不支持 YouTube Premium"
else
green " 本机 $2 支持 YouTube Premium, 角标: ${resultYoutube}"
fi
else
red " 要进行的测试 Url为空! "
fi
}
function startNetflixTest(){
echo
green " =================================================="
green " Netflix 非自制剧解锁 检测脚本 By JinWYP"
red " 本脚本无法检测出使用 V2ray 服务器端路由规则解锁Netflix"
red " 需要在 V2ray 客户端上运行本脚本才可以检测成功"
green " =================================================="
echo
if [[ -n "$1" ]]; then
isAutoRefreshWarp="true"
autoRefreshWarpIPStart
else
testIPV6Enabled
testNetflixAll "ipv4"
testNetflixAll "ipv6"
testNetflixAll "ipv4warp"
green " ===== Youtube Premium 准备开始检测 ====="
testYoutubeAll "ipv4"
testYoutubeAll "ipv6"
testYoutubeAll "ipv4warp"
fi
}
startNetflixTest "$1"