ShenHongFei / utorrent-block-xunlei

A small script for uTorrent that blocks Xunlei(Thunder) clients automatically. uTorrent 自动屏蔽迅雷脚本
170 stars 20 forks source link
anti-leech bittorrent thunder utorrent xunlei

uTorrent 自动屏蔽迅雷脚本 (Xunlei Blocker of uTorrent)

utorrent-block-xunlei icon

uTorrent 自动屏蔽迅雷脚本

Xunlei Blocker of uTorrent

github release npm version npm downloads

中文 | English

屏蔽功能

每隔 20 秒,自动检查 uTorrent 已连接的用户列表,找出迅雷客户端,强制断开,不给吸血雷上传任何数据,并将用户 IP 加入黑名单阻止其再次连接,把带宽留给正规 BT 客户端

屏蔽策略

理由:

屏蔽列表

-XL0012-
Xunlei/

7.x.x.x Xfplay
FDM
dandanplay
Mozilla
go.torrent aria2

屏蔽算法

  1. 根据 uTorrent 的 WebUI API 发送 HTTP 请求,获取所有已连接用户 (peers) 信息
  2. 按照用户 (peer) 的客户端名称 (client) 筛选出使用迅雷的用户,将 IP 写入 ipfilter.dat 文件
  3. 发送 HTTP 请求让 uTorrent 重新加载 ipfilter.dat
  4. uTorrent 禁止 ipfilter.dat 中的 IP 连接

代码逻辑

this.should_block = (() => {
    if (!/-XL0012-|Xunlei|^7\.|aria2|Xfplay|dandanplay|FDM|go\.torrent|Mozilla/i.test(this.client)) return false

    const [state] = this.torrent.state
    if (state === '做种')
        return this.upload_speed > 10 * 2 ** 10  // 我方上传速度大于 10 KB/s
    if (state === '下载')
        return this.uploaded > this.downloaded * 10 + 5 * 2**20  // 累计吸血量大于 `10 × 累计上传量 + 5MB`

    return false
})()

其他功能

预览

命令行监控

命令行监控

resume.dat 解析及文件重定向

resume.dat 解析及文件重定向

使用方法

  1. 确保 uTorrent 是 3.0 以上版本(不支持 2.x 版本),并开启 WebUI (网页界面)
    1.1 打开 uTorrent 设置 > 高级 > 网页界面
    1.2 选上 "启用网页界面", 并在下方填写用户和密码, 记下来, 作为命令行 --username--password 参数的值
  2. 在 "uTorrent 设置 > 连接 > 监听端口 > 传入连接所使用的端口" 中查看设置的端口号,记下来,作为命令行 --port 参数的值
  3. 在 uTorrent 数据目录中(路径可能是 C:/Users/<用户名>/AppData/Roaming/uTorrent/ipfilter.dat ,该目录下应该有 resume.dat 文件存在)保证 ipfilter.dat 文件存在(若不存在则新建空白 ipfilter.dat 文件),脚本会在原有 ipfilter.dat 文件内容之后添加被屏蔽的 IP,不影响已有内容及其功能
  4. 在 releases 中下载 utorrent-block-xunlei.exe, 下载地址: https://github.com/ShenHongFei/utorrent-block-xunlei/releases
  5. 查看用法: utorrent-block-xunlei.exe --help
    
    Usage: utorrent-block-xunlei --port 50050 --username tom --password 123456 --ipfilter "C:/Users/tom/AppData/Roaming/uTorrent/ipfilter.dat"

Xunlei Blocker of uTorrent

Options: -V, --version output the version number --hostname 可选参数, uTorrent WebUI 主机的 hostname, 默认为本机 127.0.0.1, 也可设置远程主机 IP 或域名 (default: "127.0.0.1") --port 必传参数, "uTorrent 设置 > 连接 > 监听端口 > 传入连接所使用的端口" 中设置的端口号 --username 必传参数, "uTorrent 设置 > 高级 > 网页界面 > 身份验证 > 用户" 中设置的用户名 --password 必传参数, "uTorrent 设置 > 高级 > 网页界面 > 身份验证 > 密码" 中设置的密码 --ipfilter 必传参数, uTorrent 数据目录中 ipfilter.dat 文件的完整路径,如: C:/Users/tom/AppData/Roaming/uTorrent/ipfilter.dat --interval 可选参数, 检测 peers 的间隔(秒), 默认每隔 20 秒检测并屏蔽一次 (default: "20") --interval-reset 可选参数, 间隔 interval 秒自动重置当前时间间隔内被动态屏蔽的 IP,默认间隔 2 小时 (default: "7200") -h, --help display help for command


6. 启动 blocker (修改下参数的值): `utorrent-block-xunlei --port 50050 --username shf --password 123456 --ipfilter "C:/Users/shf/AppData/Roaming/uTorrent/ipfilter.dat"`

7. (可选,不影响屏蔽功能) 在 uTorrent 中开启屏蔽日志,查看被屏蔽的连接请求
    4.1 在 uTorrent 下方的日志面板中点击右键
    4.2 勾选 `记录用户通讯信息 > 记录拦截连接`
    4.3 有被屏蔽的用户连接时可以在 uTorrent 日志面板中看到类似下面的日志
```text
[2018-11-22 19:03:43]  Loaded ipfilter.dat (51 entries)
[2018-11-22 19:03:46]  IpFilter blocked peer 223.81.192.235
[2018-11-22 19:03:49]  IpFilter blocked peer 223.81.192.235
[2018-11-22 19:04:06]  IpFilter blocked peer 223.81.192.235
[2018-11-22 19:04:21]  IpFilter blocked peer 183.25.54.216
[2018-11-22 19:04:46]  IpFilter blocked peer 223.81.192.235
...
  1. 实时控制,查看状态,REPL 在 utorrent-block-xunlei 命令行窗口中输入 utorrent 可通过 REPL 查看其属性,调用其方法 如输入 utorrent.print_blockeds() 可查看被动态屏蔽的 IP

  2. 退出 utorrent-block-xunlei 时需在命令行窗口中输入 exit(), 以保证 ipfilter.dat 恢复到运行前的状态,不残留动态屏蔽的 IP

API

  1. 安装最新版 Node.js: https://nodejs.org/en/
  2. 安装 npm 包 utorrent-block-xunlei : npm i utorrent-block-xunlei
import { UTorrent, Torrent, Peer, TorrentData, TorrentFile, ResumeData } from 'utorrent-block-xunlei'

let utorrent = await UTorrent.connect({
    root_url: 'http://127.0.0.1:50050/gui/',
    username: 'xxx',
    password: 'xxxxxxxx',
    ipfilter_dat: 'C:/Users/xxx/AppData/Roaming/uTorrent/ipfilter.dat',
    interval: 20 * 1000,
    print: {
        torrents: '所有',
        peers: true
    }
})

utorrent.start_blocking()

utorrent.hide_display()

utorrent.show_display()

utorrent.stop_blocking()

utorrent.reset_ipfilter()

utorrent.block_peers()

utorrent.print_blockeds()

utorrent.state

相关项目