Code Monkey home page Code Monkey logo

utorrent-block-xunlei's Introduction

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 客户端

屏蔽策略

  • 下方屏蔽列表中的非法客户端才会被屏蔽
  • 任务处于做种状态时:屏蔽吸血速度大于 10 KB/s 的非法客户端,将带宽留给合法客户端
  • 任务处于下载状态时,对有上传流量的非法客户端放宽处理:只屏蔽累计吸血量大于 10 × 累计上传量 + 5MB 的非法客户端

理由:

  • 过于频繁的重载 ipfilter.dat 可能影响上传、下载速度,因此设置了一个阈值,忽略已连接但吸血速度过低的非法客户端
  • 下载时部分非法客户端也有积极上传,为了提升我方的下载速度,暂时赦免他们,也给他们上传

屏蔽列表

-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
})()

其他功能

  • 支持 IP 定位,显示地理位置

  • 批量可编程式修改 uTorrent 的 resume.dat 内保存的任务信息,从而:

    • 在任务或下载文件丢失后,通过修改 resume.dat 跳过文件强制检查,继续做种
    • 可以批量修改本地文件的路径和文件名,并建立到原有种子文件内文件信息的映射,保持继续做种的能力
    • 批量重命名任务,恢复上传量、下载量
    • 提供 API 修改 resume.dat 内保存的任何信息
  • 命令行监控,实时查看 peers 情况

预览

命令行监控

命令行监控

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

  2. (可选,不影响屏蔽功能) 在 uTorrent 中开启屏蔽日志,查看被屏蔽的连接请求 4.1 在 uTorrent 下方的日志面板中点击右键 4.2 勾选 记录用户通讯信息 > 记录拦截连接 4.3 有被屏蔽的用户连接时可以在 uTorrent 日志面板中看到类似下面的日志

[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

相关项目

utorrent-block-xunlei's People

Contributors

shenhongfei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

utorrent-block-xunlei's Issues

不知道aria2是否也能通过类似的思路屏蔽迅雷呢?

aria2的BT功能似乎比较简单,也没有API,只有通过RPC与aria2server通信,希望repo主有时间看一下。

毕竟使用服务器挂BT的用户也大有人在,相比较而言服务器因为长时间挂机所以被吸血的时间会更久、受迅雷毒害更深一点。

影响下载速度

运行一小时左右下载速度急剧下降,手动清理ipfilter.dat之后速度提升。
版本3.5.5 能否加入自动清理ipfilter.dat功能

求帮助

D:\uTorrentBlockXunlei>nodejs\node.exe utorrent.js
(node:11900) UnhandledPromiseRejectionWarning: StatusCodeError: 401 - ""
at new StatusCodeError (D:\uTorrentBlockXunlei\node_modules\request-promise-native\node_modules\request-promise-core\lib\errors.js:32:15)
at Request.plumbing.callback (D:\uTorrentBlockXunlei\node_modules\request-promise-native\node_modules\request-promise-core\lib\plumbing.js:104:33)
at Request.RP$callback [as _callback] (D:\uTorrentBlockXunlei\node_modules\request-promise-native\node_modules\request-promise-core\lib\plumbing.js:46:31)
at Request.self.callback (D:\uTorrentBlockXunlei\node_modules\request\request.js:185:28)
at Request.emit (events.js:189:13)
at Request. (D:\uTorrentBlockXunlei\node_modules\request\request.js:1161:14)
at Request.emit (events.js:189:13)
at IncomingMessage. (D:\uTorrentBlockXunlei\node_modules\request\request.js:1083:18)
at Object.onceWrapper (events.js:277:13)
at IncomingMessage.emit (events.js:194:15)
(node:11900) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11900) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

D:\uTorrentBlockXunlei>pause
请按任意键继续. . .
这个问题如何解决呀?是我下载出问题了吗?

xunlei/0.0.1.8无法屏蔽

作者大大还在吗?xunlei/0.0.1.8 这种的还是没有屏蔽 xunlei0012-XXX这种倒是一下子就给屏蔽了。

webui浏览器访问正常但是脚本运行Err400

webui版本 v0.388 utorrent2.0.4,webui是加那个webui.zip装上去的,脚本里/gui/没落下,直接用浏览器访问没有问题。但是脚本不管是本机走127.0.0.1还是别的机器走ip都是invalid request。
跪谢

同一個IP一直沒有被block

今天遇到一個奇怪的現象

同一個IP,已經被寫到 ipfilter.dat 裡了,也確定 ipfilter 有作用,但就是一直沒被 ut 踢掉

未命名
圖片 2019-08-02 10-22-55
圖片 2019-08-02 10-23-39

之前沒遇過這樣的現象,重開 uTorrent 及 utorrent-block-xunlei 後,也正常踢掉其它IP了

不曉得大家有沒有遇過類似的情況?

建议把定时清理ipfilter.dat写入脚本

时间上自己可以调整,例如一天、一小时、一分钟什么的,用秒来计算吧。

另外,为了减少读取ipfilter.dat对硬盘的影响,不知把这个文件挂在到内存怎么样?例如(ubuntu下):
mount -o bind /run/user/0/ipfilter.dat /run/utorrent/ipfilter.dat

关于FDM被屏蔽的原因是什么

十几年前我也曾经是个迅雷用户(当然后来知道恶劣行径以后就没再用过了),不管是FDM,aria2,uT,qBT,BitComet,这些年都有用过(最后日常用qBT作为p2p下载的客户端),但注意到您这里把FDM视作需要屏蔽的客户端之一,在代码中
https://github.com/ShenHongFei/utorrent-block-xunlei/blame/7c25a93e2e1b49925a2e9d0745242ef682f9d3a1/index.ts#L96
可以看到这一点

而在 tonyhsie/qBittorrentBlockXunlei#3 的讨论中,仓库主 tonyhsie 表示他是因为您这个项目封FDM所以有样学样的封FDM,而对FDM的指控并不像迅雷或者一些PCDN客户端一样有明确的“作恶”的证据(当然也有其他项目反馈称其peerID不够标准),想问一下您ban掉这个客户端是出于什么原因,以及aria2是什么原因。(至于其他一些播放器倒是没啥疑问)

(顺便,如果您感兴趣,或许可以考虑ban一下 anacrolix/torrent#891 (comment) 中提到的这些如“Taipei-Torrent dev”之类的恶意下载的客户端。)

给各位总结一下我瞎折腾时遇到的问题

简单说是对自己蜜汁自信,粗心大意修改代码导致的各种问题。基本上按主页的说明来操作是不会有任何问题的。

1.运行.bat不需要管理员权限,不管你有没有开UAC,直接运行都能生效。所以不存在编辑这个文件改路径的问题。
2.所以也不需要单独再安装nodejs,压缩包里有了,也不用系统路径里添加nodejs。
3.utorrent.js文件编辑的时候,双击选中字段的话会把引号和逗号也选中,补了引号不要忘记补逗号。
4.本人Win10系统,复制uTorrent根目录路径下来是“\”,虽然不清楚路径里“\”和“/”不同是否有影响,但如果要改过来的话,不要用全文替换,文件中本身有很多“\”。

PS.运行成功后可以最小化,每30秒会做一次屏蔽匹配。

你好,希望解决人工手动屏蔽无效的问题

就是我手动去屏蔽一些吸血不上传的正规客户端,就是复制它的ip地址粘贴到ipfilter.dat后,过了一会这个吸血的正规客户端又出现在我的下载列表里了,能否弄个代码什么的让这些手动屏蔽的吸血正规客户端不再恢复,我觉得把这个问题解决了,这个脚本就又上一层楼了。对了,我现在用的版本仍然是utorrent-block-xunlei-v1.0

免安装版问题

你好。我使用的免安装没有C盘appdate没有ipfilter,然后我自己创建了一个,编辑脚本后依然无法使用,必须要用安装版吗??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.