netflix dns自动切换

2022-03-28 06:56:16   工作备份

 

由于netflix解锁不稳定,经常需要手动更换dns,于是写了个shell脚本来自动处理这些事

  1. -rw-r--r-- 1 root root 145 3 26 09:47 ip.txt
  2. -rw-r--r-- 1 root root 105598 3 28 12:00 log.log
  3. -rwxr-xr-x 1 root root 647 3 15 10:11 netflix.sh
  4. -rwxr-xr-x 1 root root 4784128 12 8 04:41 nf

其中nf是GitHub上的奈非检测程序

  1. 安装
  2. wget -O nf https://github.com/sjlleo/netflix-verify/releases/download/2.61/nf_2.61_linux_amd64 && chmod +x nf && clear && ./nf

然后需要更换的dns从dns解锁服务商处获得,如下

  1. 5.180.78.164
  2. 195.85.19.45
  3. 103.149.46.114

最后是shell脚本

  1. #!bin/bash
  2. dir=$(cd "$(dirname "$0")";pwd)
  3. c=0
  4. for line in `cat $dir/ip.txt`
  5. do
  6. patter="^(\w+\.){3}\w+$"
  7. if [[ "$line" =~ $patter ]]; then
  8. ip=$line
  9. array[$c]=$ip
  10. ((c++))
  11. fi
  12. done
  13. check(){
  14. info=`$dir/nf`
  15. if [[ $info =~ "您的出口IP完整解锁Netflix" ]]; then
  16. return 1
  17. else
  18. return 0
  19. fi
  20. }
  21. check
  22. if [[ $? == 1 ]]
  23. then
  24. exit;
  25. fi
  26. for i in ${!array[@]}
  27. do
  28. var=${array[i]}
  29. sed -i "s/localdomain\^\$dnsrewrite=[^\']*/localdomain\^\$dnsrewrite=$var/g" /etc/AdGuardHome/AdGuardHome.yaml
  30. $(/etc/AdGuardHome/AdGuardHome -s restart)
  31. sleep 2
  32. check
  33. if [[ $? == 1 ]]
  34. then
  35. echo "替换成功:$var"
  36. exit;
  37. fi
  38. done

本脚本配合adguardhome使用,服务器需要指定adguardHome解析dns,然后自定义过滤规则

  1. #netflix
  2. ||localdomain^$dnsrewrite=5.180.78.164
  3. ||netflix.ca^$dnsrewrite=NXDOMAIN;;
  4. ||fast.com^$dnsrewrite=NXDOMAIN;;
  5. ||netflix.com^$dnsrewrite=NXDOMAIN;;
  6. ||netflix.net^$dnsrewrite=NXDOMAIN;;
  7. ||netflixinvestor.com^$dnsrewrite=NXDOMAIN;;
  8. ||netflixtechblog.com^$dnsrewrite=NXDOMAIN;;
  9. ||nflxext.com^$dnsrewrite=NXDOMAIN;;
  10. ||nflximg.com^$dnsrewrite=NXDOMAIN;;
  11. ||nflximg.net^$dnsrewrite=NXDOMAIN;;
  12. ||nflxsearch.net^$dnsrewrite=NXDOMAIN;;
  13. ||nflxso.net^$dnsrewrite=NXDOMAIN;;
  14. ||nflxvideo.net^$dnsrewrite=NXDOMAIN;;
  15. ||amazonaws.com^$dnsrewrite=NXDOMAIN;;

脚本会自动检测当前netflix是否解锁,并逐一使用ip.txt内的ip修改adguardHome配置,然后继续检测

netlfix.sh需要授予执行权限

  1. chmod +x netflix.sh

配置定时任务以运行

  1. */2 * * * * bash /root/netflix/netflix.sh