From 4e2a986248a245bf7c94ebcbb9bd8f6a85557e36 Mon Sep 17 00:00:00 2001 From: jqtmviyu Date: Tue, 30 Jul 2024 12:39:11 +0800 Subject: [PATCH] fix: :bug: update readme --- README.md | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 388a76a..9ac5a7b 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,10 @@ username="用户名" password="密码" host="127.0.0.1" port=9091 -chain="OUTPUT" # 定义iptables链名称 -custom_chain="CUSTOM_CHAIN" # 定义自定义链名称 +ipv4_chain="OUTPUT" # 定义IPv4主链名称 +ipv6_chain="OUTPUT" # 定义IPv6主链名称 +ipv4_custom_chain="CUSTOM_CHAIN_IPV4" # 定义IPv4自定义链名称 +ipv6_custom_chain="CUSTOM_CHAIN_IPV6" # 定义IPv6自定义链名称 # 获取所有传输任务的对等节点IP地址 echo "获取传输任务对等节点的IP地址..." @@ -38,27 +40,27 @@ hour=$(date "+%H") # 如果当前时间是每4小时的半小时(例如,0:30,4:30等) if [ "$minute" -eq 30 ] && [ $(($hour % 4)) -eq 0 ]; then - echo "当前时间是每4小时的半小时, 清空自定义链 $custom_chain" - # ${minute#0} 去掉前导的0 - # (()) 用于数值运算,${hour#0} 去掉前导的0 - iptables -F $custom_chain # 清空IPv4自定义链 - ip6tables -F $custom_chain # 清空IPv6自定义链 + echo "当前时间是每4小时的半小时, 清空自定义链 $ipv4_custom_chain 和 $ipv6_custom_chain" + iptables -F $ipv4_custom_chain # 清空IPv4自定义链 + ip6tables -F $ipv6_custom_chain # 清空IPv6自定义链 fi # 检查并创建自定义链(如果不存在) echo "检查并创建自定义链(如果不存在)..." -iptables -L $custom_chain &> /dev/null || (echo "创建IPv4自定义链 $custom_chain"; iptables -N $custom_chain) -ip6tables -L $custom_chain &> /dev/null || (echo "创建IPv6自定义链 $custom_chain"; ip6tables -N $custom_chain) +iptables -L $ipv4_custom_chain &> /dev/null || (echo "创建IPv4自定义链 $ipv4_custom_chain"; iptables -N $ipv4_custom_chain) +ip6tables -L $ipv6_custom_chain &> /dev/null || (echo "创建IPv6自定义链 $ipv6_custom_chain"; ip6tables -N $ipv6_custom_chain) # 确保自定义链在主链中被调用 -echo "确保自定义链在主链 $chain 中被调用..." -iptables -C $chain -j $custom_chain &> /dev/null || (echo "添加 $custom_chain 到 $chain"; iptables -A $chain -j $custom_chain) -ip6tables -C $chain -j $custom_chain &> /dev/null || (echo "添加 $custom_chain 到 $chain"; ip6tables -A $chain -j $custom_chain) +echo "确保自定义链在主链中被调用..." +iptables -C $ipv4_chain -j $ipv4_custom_chain &> /dev/null || (echo "添加 $ipv4_custom_chain 到 $ipv4_chain"; iptables -A $ipv4_chain -j $ipv4_custom_chain) +ip6tables -C $ipv6_chain -j $ipv6_custom_chain &> /dev/null || (echo "添加 $ipv6_custom_chain 到 $ipv6_chain"; ip6tables -A $ipv6_chain -j $ipv6_custom_chain) # 获取当前的自定义链规则 -echo "获取当前自定义链 $custom_chain 规则..." -rules=$(iptables -nL $custom_chain; ip6tables -nL $custom_chain) -echo "当前自定义链规则: $rules" +echo "获取当前自定义链规则..." +ipv4_rules=$(iptables -nL $ipv4_custom_chain) +ipv6_rules=$(ip6tables -nL $ipv6_custom_chain) +echo "当前IPv4自定义链规则: $ipv4_rules" +echo "当前IPv6自定义链规则: $ipv6_rules" # 遍历指定的客户端名称 for client in xunlei xl thunder gt0002 xl0012 xfplay dandanplay dl3760 qq hp dt xm go taibei sp StellarPlayer flashget torrentstorm github ljyun cacao "-tt" "qbittorrent/3.3.15" @@ -68,19 +70,19 @@ do for i in $(echo "$ips" | grep -F -i -- "$client" | cut -d " " -f 1) do # 检查当前IP是否已经在规则中 - if echo "$rules" | grep -q $i; then + if echo "$ipv4_rules" | grep -q $i || echo "$ipv6_rules" | grep -q $i; then echo -n "$i 已在规则中, " # 如果在规则中,输出IP else echo -n "$i 不在规则中, " # 如果不在规则中,输出IP并说明未在规则中 # 检查是否为IPv6地址 if echo "$i" | grep -q ":" ; then - # 如果是IPv6地址,添加DROP规则到自定义链 - echo "添加IPv6地址 $i 到自定义链 $custom_chain" - ip6tables -I $custom_chain -d $i -j DROP + # 如果是IPv6地址,添加DROP规则到IPv6自定义链 + echo "添加IPv6地址 $i 到自定义链 $ipv6_custom_chain" + ip6tables -I $ipv6_custom_chain -d $i -j DROP else - # 如果是IPv4地址,添加DROP规则到自定义链 - echo "添加IPv4地址 $i 到自定义链 $custom_chain" - iptables -I $custom_chain -d $i -j DROP + # 如果是IPv4地址,添加DROP规则到IPv4自定义链 + echo "添加IPv4地址 $i 到自定义链 $ipv4_custom_chain" + iptables -I $ipv4_custom_chain -d $i -j DROP fi fi done