Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
410154425 authored Sep 13, 2023
1 parent a4237e1 commit c96fb28
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 70 deletions.
4 changes: 1 addition & 3 deletions AdGuardHome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ dns:
bootstrap_dns:
- 10.35.53.10:3553
fallback_dns:
- https://223.6.6.6/dns-query
- https://120.53.53.53/dns-query
- '#不可填写其它dns,否则可能造成无限循环的dns查询'
- '#此处留空不要填'
all_servers: false
fastest_addr: false
fastest_timeout: 1s
Expand Down
18 changes: 9 additions & 9 deletions mode.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#使用前需关闭私人dns,不可用wap接入点,AdHome后台管理地址http://127.0.0.1:3000,用户名/密码root (若面具页面显示运行中,但无法打开后台,则可能是系统被精简web服务相关导致,或者换浏览器试下),本机流量数据或wifi都支持过滤,AdHome后台有数据变化代表模块生效,以下所有配置参数修改即时生效,无需重启。

#模式选择:模式几就填几,模式1在切换网络时可能会有3秒时间不过滤,模式2或3则不会,各有优缺点,详细看下面介绍
#模式选择:模式几就填几,三种模式都是过滤所有53端口的DNS流量,详情看下面介绍
mode=1

#模式1:过滤本机默认的DNS流量(走VPN的DNS流量不过滤)。该模式下,AdHome后台里的DNS上游10.35.53.10:3553(相当于本机默认的DNS,一般用于校园网认证或其它内网解析)在VPN关闭状态下可用有效,在VPN开启状态下自动失效
#模式1:兼容性强,可解析内网域名。该模式下,AdHome后台里的DNS上游10.35.53.10:3553(相当于本机默认的DNS,一般用于校园网认证或其它内网解析)在VPN关闭时可解析内网域名,在VPN开启时则不可解析内网域名

#模式2(推荐使用):过滤所有53端口的DNS流量(包括走VPN的DNS流量,但VPN软件若设置不当会没网)。该模式下,AdHome后台里的DNS上游10.35.53.10:3553自动失效。
#模式2(推荐使用):纯DOH解析,防DNS劫持,较强的隐私性。该模式下,AdHome后台里的DNS上游10.35.53.10:3553自动失效,不可解析内网域名

#模式3(实验性):过滤原理与模式2相同。另外在该模式下,AdHome后台的DNS上游可以填写域名类型的DoH/DoT/DoQ(不可填写普通53端口的dns,仅模式3可选择删除默认的dns上游),同时Bootstrap DNS服务器必须且仅可填写为10.35.53.10:3553。
#模式3(实验性):该模式下,AdHome后台的DNS上游可以填写域名类型的DoH/DoT/DoQ(不可填写普通53端口的DNS,仅模式3可选择删除默认的DNS上游,不可以打开VPN,否则可能没网,不可解析内网域名),同时后台的Bootstrap DNS服务器必须且仅可填写为10.35.53.10:3553。

#用于解析模式3中DNS上游DoH/DoT/DoQ域名的IP地址,只可填一个,必须包含端口。
B_DNS=114.114.114.114:53
Expand All @@ -20,18 +20,18 @@ port_testing=1

#↓↓↓特殊使用环境说明↓↓↓

#VPN类软件:若使用模式1,VPN类软件可设置域名分流或应用分流的方式实现不走VPN的过滤,走VPN的不过滤。若使用模式2或3,SSR软件默认设置可用可过滤、V2RayNG软件默认设置可用可过滤,Clash软件默认设置加勾选网络-系统代理(可用但无法过滤),其它软件自行测试。
#VPN类软件:VPN软件若设置不当会没网。SSR软件默认设置可用可过滤、V2RayNG软件默认设置可用可过滤,Clash软件默认设置加勾选网络-系统代理(有网络但无法过滤),其它软件自行测试。

#免流类Magisk模块:免流类模块在全局规则模式下,AdHome的模式1、模式2或3都可以使用
#免流类Magisk模块:免流类模块在全局规则模式下,可用可过滤

#翻墙类Magisk模块:AdHome后台里的DNS上游需全部删除,加一条:127.0.0.1:X (X是翻墙模块的监听端口),AdHome的模式1、模式2或3都可以使用
#翻墙类Magisk模块:AdHome后台里的DNS上游需全部删除,加一条:127.0.0.1:X (X是翻墙模块的监听端口),可用可过滤

#路由端翻墙插件:AdHome后台里的DNS上游仅保留10.35.53.10:3553,其它删除,仅可使用模式1,且不可以打开VPN(否则没网)。

#模块默认监听端口为5591,若你有特殊需求,可在AdGuardHome.yaml文件修改 port: 5591 需要重启生效。(注意:若使用53端口,则无法开启热点)

#模块默认仅支持本机打开后台,若你需要同局域网其它设备打开后台,可在AdGuardHome.yaml文件修改 address: 127.0.0.1:3000为 address: 0.0.0.0:3000 需要重启生效
#模块默认仅支持本机打开后台,若你需要同局域网其它设备打开后台,可在AdGuardHome.yaml文件修改 address: 127.0.0.1:3000为 address: 0.0.0.0:3000 需要重启生效

#'暂停过滤.sh'和'恢复过滤.sh'两个sh脚本文件内容可以配合第三方软件使用,比如控制中心磁贴类软件(推荐Anywhere)可实现控制中心快捷控制暂停或恢复过滤,情景任务类软件可实现指定情景自动暂停或恢复过滤。(因DNS有缓存因素存在,若当前app有对应的DNS缓存,则有可能不会马上见效)

#如果模块无法获取到本机默认的dns,将无法使用模式1,模块将自动强制使用模式2或3,Magisk应用里可查看当前模式,或执行testing.sh脚本可查询当前模式以及其它更多信息。
#如果模块无法获取到本机默认的dns,将无法使用模式1,模块将自动强制使用模式2,Magisk应用里可查看当前模式,或执行testing.sh脚本可查询当前模式以及其它更多信息。
4 changes: 2 additions & 2 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=AdGuardHome
name=AdGuardHome模块
version=20230912
versionCode=2023091200
version=20230913
versionCode=2023091300
author=top大佬(酷安)
description=[ - ] 通过DNS层面过滤广告、防DNS劫持,使用前请先详读mode.conf文件,支持订阅过滤规则,后台地址http://127.0.0.1:3000,用户名/密码root,配置文件:/data/adb/modules/AdGuardHome/mode.conf。
#by topdalao
3 changes: 2 additions & 1 deletion testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ else
fi
HostDns="$(echo "$Network" | egrep 'NetworkAgentInfo\{' | sed -n 's/.* DnsAddresses: \[//g;s/\].*//g;s/ //g;s/\///g;s/,/\\n/g;p')"
HostDns_n="$(echo -e "$HostDns" | egrep -v ':')"
type="$(cat "$MODDIR/type")"
mode="$(cat "$MODDIR/module.prop" | egrep '^description=' | sed -n 's/.*=\[//g;s/\].*//g;p')"
mode_conf="$(cat "$MODDIR/mode.conf")"
Lock_sleep="$(echo "$mode_conf" | egrep '^Lock_sleep=' | sed -n 's/.*=//g;$p')"
Expand All @@ -42,7 +43,7 @@ echo --------- 获取dns ----------
echo "$HostDns_n"
echo "如果获取dns为空,但下面网络信息里却有dns,可找作者适配"
echo ---------- 模式 ------------
echo "$mode"
echo "$mode ,$type"
echo "息屏不过滤$Lock_sleep"
echo "AdHome端口启动检测$port_testing"
echo "$port_yaml"
Expand Down
103 changes: 49 additions & 54 deletions topdalao
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ if [ -n "$Network" ]; then
WIFI_Dns="$(echo "$Network" | egrep 'type: WIFI|ni\{WIFI' | sed -n 's/.* DnsAddresses: \[//g;s/\].*//g;s/ //g;p')"
if [ ! -n "$WIFI_Dns" ]; then
Network="$(echo "$NetworkAgentInfo" | egrep 'type: MOBILE|ni\{MOBILE')"
else
HostDns_Dual_Path="$(echo "$NetworkAgentInfo" | egrep 'type: MOBILE|ni\{MOBILE' | sed -n 's/.* DnsAddresses: \[//g;s/\].*//g;s/ //g;s/\///g;s/,/\\n/g;p')"
Dual_Path_list="$(echo -e "$HostDns_Dual_Path" | egrep '\.' | egrep -v ':')"
fi
else
Network="$(echo "$NetworkAgentInfo" | egrep 'type: MOBILE|ni\{MOBILE')"
Expand All @@ -98,36 +95,58 @@ if [ -n "$HostDns_3" ]; then
else
HostDns_1="$(echo -e "$HostDns" | egrep '\.' | egrep -v ':' | sed -n '1p')"
fi
type="$(cat "$MODDIR/type")"
mode="$(echo "$mode_conf" | egrep '^mode=' | sed -n 's/.*=//g;$p')"
if [ "$mode" = "3" ]; then
B_DNS="$(echo "$mode_conf" | egrep '^B_DNS=' | sed -n 's/.*=//g;$p')"
if [ ! -n "$B_DNS" ]; then
B_DNS='114.114.114.114:53'
fi
natTOPHOME="$(iptables -t nat -n -L TOPHOME)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep '10.35.53.10' | wc -l)"
TOPHOME_HostVPN="$(echo "$natTOPHOME" | egrep "$B_DNS" | wc -l)"
if [ -n "$natTOPHOME" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" ]; then
iptables -t nat -F TOPHOME
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d 10.35.53.10 -p udp --dport 3553 -j DNAT --to-destination "$B_DNS"
sed -i 's/\[.*\]/\[ 模式3 运行中 \]/g' "$MODDIR/module.prop"
HostVPN="$(echo "$NetworkAgentInfo" | sed -n 's/extra:.*//g;p' | egrep 'VPN' | wc -l)"
if [ "$HostVPN" != "0" ]; then
natTOPHOME="$(iptables -t nat -n -L TOPHOME)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep '10.35.53.10' | wc -l)"
TOPHOME_HostVPN="$(echo "$natTOPHOME" | egrep '127.0.0.1:9' | wc -l)"
if [ -n "$natTOPHOME" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" -o "$type" != "32" ]; then
iptables -t nat -F TOPHOME
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d 10.35.53.10 -p udp --dport 3553 -j DNAT --to-destination 127.0.0.1:9
echo "32" > "$MODDIR/type"
sed -i 's/\[.*\]/\[ 模式3+VPN 运行中 \]/g' "$MODDIR/module.prop"
fi
else
iptables -t nat -N TOPHOME
fi
else
iptables -t nat -N TOPHOME
B_DNS="$(echo "$mode_conf" | egrep '^B_DNS=.*\..*\..*\..*:' | sed -n 's/.*=//g;$p')"
if [ ! -n "$B_DNS" ]; then
B_DNS='114.114.114.114:53'
fi
natTOPHOME="$(iptables -t nat -n -L TOPHOME)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep '10.35.53.10' | wc -l)"
TOPHOME_HostVPN="$(echo "$natTOPHOME" | egrep "$B_DNS" | wc -l)"
if [ -n "$natTOPHOME" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" -o "$type" != "31" ]; then
iptables -t nat -F TOPHOME
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d 10.35.53.10 -p udp --dport 3553 -j DNAT --to-destination "$B_DNS"
echo "31" > "$MODDIR/type"
sed -i 's/\[.*\]/\[ 模式3 运行中 \]/g' "$MODDIR/module.prop"
fi
else
iptables -t nat -N TOPHOME
fi
fi
elif [ "$mode" = "2" -o ! -n "$HostDns_1" ]; then
natTOPHOME="$(iptables -t nat -n -L TOPHOME)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep '10.35.53.10' | wc -l)"
TOPHOME_HostVPN="$(echo "$natTOPHOME" | egrep '127.0.0.1:9' | wc -l)"
if [ -n "$natTOPHOME" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" -o "$type" != "21" ]; then
iptables -t nat -F TOPHOME
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d 10.35.53.10 -p udp --dport 3553 -j DNAT --to-destination 127.0.0.1:9
echo "21" > "$MODDIR/type"
sed -i 's/\[.*\]/\[ 模式2 运行中 \]/g' "$MODDIR/module.prop"
fi
else
Expand All @@ -137,55 +156,31 @@ else
HostVPN="$(echo "$NetworkAgentInfo" | sed -n 's/extra:.*//g;p' | egrep 'VPN' | wc -l)"
if [ "$HostVPN" != "0" ]; then
natTOPHOME="$(iptables -t nat -n -L TOPHOME)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep "$HostDns_1" | wc -l)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep '10.35.53.10' | wc -l)"
TOPHOME_HostVPN="$(echo "$natTOPHOME" | egrep '127.0.0.1:9' | wc -l)"
if [ -n "$natTOPHOME" ]; then
if [ "$TOPHOME_HostDns" != "2" -o "$TOPHOME_HostVPN" != "1" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" -o "$type" != "12" ]; then
iptables -t nat -F TOPHOME
HostDns_list="$(echo -e "$HostDns" | egrep '\.' | egrep -v ':')"
for i in $HostDns_list ; do
if [ -n "$i" -a "$i" != "$HostDns_1" ]; then
iptables -t nat -A TOPHOME -d "$i" -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d "$i" -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
fi
done
for i in $Dual_Path_list ; do
if [ -n "$i" -a "$i" != "$HostDns_1" ]; then
iptables -t nat -A TOPHOME -d "$i" -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d "$i" -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
fi
done
iptables -t nat -A TOPHOME -d "$HostDns_1" -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d "$HostDns_1" -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d 10.35.53.10 -p udp --dport 3553 -j DNAT --to-destination 127.0.0.1:9
echo "12" > "$MODDIR/type"
sed -i 's/\[.*\]/\[ 模式1+VPN 运行中 \]/g' "$MODDIR/module.prop"
fi
else
iptables -t nat -N TOPHOME
fi
else
natTOPHOME="$(iptables -t nat -n -L TOPHOME)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep "$HostDns_1" | wc -l)"
TOPHOME_HostDns="$(echo "$natTOPHOME" | egrep '10.35.53.10' | wc -l)"
TOPHOME_HostVPN="$(echo "$natTOPHOME" | egrep "$HostDns_1:53" | wc -l)"
if [ -n "$natTOPHOME" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" ]; then
if [ "$TOPHOME_HostDns" != "3" -o "$TOPHOME_HostVPN" != "1" -o "$type" != "11" ]; then
iptables -t nat -F TOPHOME
HostDns_list="$(echo -e "$HostDns" | egrep '\.' | egrep -v ':')"
for i in $HostDns_list ; do
if [ -n "$i" -a "$i" != "$HostDns_1" ]; then
iptables -t nat -A TOPHOME -d "$i" -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d "$i" -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
fi
done
for i in $Dual_Path_list ; do
if [ -n "$i" -a "$i" != "$HostDns_1" ]; then
iptables -t nat -A TOPHOME -d "$i" -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d "$i" -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
fi
done
iptables -t nat -A TOPHOME -d "$HostDns_1" -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d "$HostDns_1" -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p udp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME ! -d 10.35.53.10 -p tcp --dport 53 -j DNAT --to-destination "127.0.0.1:$port_yaml"
iptables -t nat -A TOPHOME -d 10.35.53.10 -p udp --dport 3553 -j DNAT --to-destination "$HostDns_1:53"
echo "11" > "$MODDIR/type"
sed -i 's/\[.*\]/\[ 模式1 运行中 \]/g' "$MODDIR/module.prop"
fi
else
Expand Down Expand Up @@ -226,4 +221,4 @@ if [ -n "$ipv6OUTPUT" ]; then
fi
fi
#by topdalao
#version=2023091200
#version=2023091300
2 changes: 1 addition & 1 deletion update.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
AdGuardHome_update,http://z23r562938.iask.in/Adguardhome_magisk,[2023091200]
AdGuardHome_update,http://z23r562938.iask.in/Adguardhome_magisk,[2023091300]
网盘:https://topdalao.lanzouo.com/b02c3cvof
密码:1111

0 comments on commit c96fb28

Please sign in to comment.