V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  p9g3IM08n0Kly  ›  全部回复第 1 页 / 共 1 页
回复总数  1
#!/bin/zsh
Username=写你的名字
#transmission webgui 的用户名
Password=写你的密码
#transmission webgui 的密码
ClientList=(Xunlei Thunder "\-XL0012\-")
#这里指定要修改的客户端列表, 每个客户端用空格分隔
ListAddress="/var/www/html/blocklist.txt"
#这里写你的 list 的储存位置, 我用的 apache 反代理

for CertainClient ($ClientList){
transmission-remote --auth $Username:$Password -t all -ip |grep $CertainClient |awk '{print $1}' | xargs -L1 -I {ip} echo "{ip}" >> "templist.txt"
}
Temp=("${(@f)$(< templist.txt)}")
#这里生成的临时文件之后会被自动清理
for EachIp in $Temp
do
if [ $(grep $EachIp $ListAddress) ]
then
echo "$EachIp exist, not adding"
else
echo "$EachIp didn't exist, adding"
echo "$EachIp - $EachIp , 0 , Autogen" >> $ListAddress
fi
done

transmission-remote --auth $Username:$Password --blocklist-update
echo "clocklist updated"
transmission-remote --auth $Username:$Password -t all --stop
echo "current session stopped, starting after 2 seconds"
sleep 2s
transmission-remote --auth $Username:$Password -t all --start
echo "session started"
rm "templist.txt"

---------------------------------------------------------

原理就是使用 Transmission-Remote 获取某特定客户端的 ip, 将其格式化输出到反代理目录下的 txt 文件中, 再同样利用 Transmission-Remote 更新 blocklist (注意, blocklist 的 url 必须要预先写好, 指向本机的反代理目录下的文件).

在更新之后, 脚本会暂停所有任务并在 2s 之后重开, 以便禁止名单生效.

建议使用 crontab 对这个脚本进行定时, 我个人是每 10min 跑一次.
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3613 人在线   最高记录 6547   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 423ms · UTC 11:23 · PVG 19:23 · LAX 04:23 · JFK 07:23
Developed with CodeLauncher
♥ Do have faith in what you're doing.