Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Add optional argument and bugfix
Browse files Browse the repository at this point in the history
--log-unknown

remove wrong identify fake FrostWire
  • Loading branch information
SeaHOH committed Aug 6, 2020
1 parent d2b8780 commit a55ca65
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 47 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
[![release status](https://img.shields.io/github/v/release/SeaHOH/ban-peers?include_prereleases&sort=semver)](https://github.com/SeaHOH/ban-peers/releases)
[![code size](https://img.shields.io/github/languages/code-size/SeaHOH/ban-peers)](https://github.com/SeaHOH/ban-peers)

Ban-Peers is checking & banning BitTorrent leech peers via Web API, working for μTorrent. The main banned are XunLei, Baidu, QQDownload, Offline download servers, other infamous leech clients, and BT players, fake clients, who reported fake progress, the fact in serious leech.
Ban-Peers wrote in Python, it is checking & banning BitTorrent leech peers via Web API, working for μTorrent. The main banned are XunLei, Baidu, QQDownload, Offline download servers, other infamous leech clients, and BT players, fake clients, who reported fake progress, the fact in serious leech.

Execute checking per 10 seconds, the banned time can be specified by the start-up parameters, default is 12 hours. In some cases,only banned for 1 hour if the torrent is seeding. At the same time, this script will not broke the existing IP ranges (non-single IP) in ipfilter, they will be stored as-is.

Does not work in old versions of μTorrent which did not provided API `getpeers`.

**Please use this script in local network**, μTorrent Web API does not support HTTPS connections, it is not safe.

[A gift](https://github.com/SeaHOH/ban-peers/issues/1) to the users of μTorrent 3 classic desktop free version, it wrote in Chinese, you can read via a translator. e.g. translate.google.com

Resist leech strongly, this is our own rights. If you feels Ban-Peers a good work, please recommend it to your friends, Thanks.

# Notices
- Does not work in old versions of μTorrent which did not provided API `getpeers`.
- **Please use this script in local network**, μTorrent Web API does not support HTTPS connections, it is not safe.
- I took preventive measures, if you stiil found a normal peer has been banned, please tell us via [issues board](https://github.com/SeaHOH/ban-peers/issues).

# Installation
Install from
[![version](https://img.shields.io/pypi/v/ban-peers)](https://pypi.org/project/ban-peers/)
Expand Down Expand Up @@ -45,11 +46,13 @@ Win XP:
Win 7 & above:
C:\Users\<username>\AppData\Roaming\uTorrent
Portable mode:
μTorrent installation folder path. To enable this mode, first put file settings.dat into it.
μTorrent installation folder path. To enable this mode, first put file
settings.dat into it.
PortableApps:
<PortableApps folder>\App\uTorrent
Android:
I don't know any informations about it, welcome to help add those informations, even Android is unavailable。
I don't know any informations about it, welcome to help add those informations,
even Android is unavailable.
Network File:
run μTorrent at other machine, setup the settings folder as a network file path.
e.g.
Expand All @@ -60,12 +63,12 @@ Network File:

```
$ ban_peers -h
Welcome using Ban-Peers 0.1.8
Welcome using Ban-Peers 0.1.11
Usage:
ban_peers [-H IP|DOMAIN] [-p PORT] [-a USERNAME:PASSWORD]
[-e HOURS] [-f FORMAT] [-C] [-X] [-P] [-L] [-R] [-h] [-v]
[IPFILTER-PATH]
[-e HOURS] [-f FORMAT] [-C] [-X] [-P] [-L] [-R] [-U]
[-h] [-v] [IPFILTER-PATH]
Checking & banning BitTorrent leech peers via Web API, working for uTorrent.
Expand Down Expand Up @@ -94,13 +97,15 @@ Optional Arguments:
Don't checking serious leech
-R, --private-check
Enable checking for private seeds
-U, --log-unknown
Logging unknown clients
-h, --help Show this help message and exit
-v, --version Show version and exit
```

```markdown
$ ban_peers -p 12345 -a username:password /var/lib/utserver
Welcome using Ban-Peers 0.1.8
Welcome using Ban-Peers 0.1.11
19:44:35 Set uTorrent setting 'bt.use_rangeblock' to False **_Won't restore after quit_**
19:44:35 uTorrent auto-banning script start running
Choose your operation: (Q)uit, (S)top, (R)estart, (P)ause/Proceed
Expand All @@ -110,7 +115,7 @@ or

```markdown
$ ban-peers
Welcome using Ban-Peers 0.1.8
Welcome using Ban-Peers 0.1.11
Please input uTorrent settings folder path or ipfilter file path:
/var/lib/utserver
Please input WebUI username: username
Expand Down
23 changes: 13 additions & 10 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
[![release status](https://img.shields.io/github/v/release/SeaHOH/ban-peers?include_prereleases&sort=semver)](https://github.com/SeaHOH/ban-peers/releases)
[![code size](https://img.shields.io/github/languages/code-size/SeaHOH/ban-peers)](https://github.com/SeaHOH/ban-peers)

通过网页 API 检查并屏蔽 BitTorrent 吸血对端,工作于 μTorrent。主要屏蔽迅雷、百毒、QQ、离线下载服务器等臭名昭著的吸血客户端,还有 BT 播放器、假冒客户端、虚假进度,以及事实上的严重吸血对端。
这是一个用 Python 写的工具,通过网页 API 检查并屏蔽 BitTorrent 吸血对端,工作于 μTorrent。主要屏蔽迅雷、百毒、QQ、离线下载服务器等臭名昭著的吸血客户端,还有 BT 播放器、假冒客户端、虚假进度,以及事实上的严重吸血对端。

每 10 秒进行一次检查,屏蔽时间可以由启动参数指定,默认为 12 小时。屏蔽吸血并不是一刀切完全屏蔽,个别会有回传且处于容忍度以内,这时不会马上屏蔽它。这是个反吸血措施,如果此下载在本机处于做种状态,那么就会马上屏蔽它们,其中判断为恶性吸血的仍然屏蔽 12 小时,无法确定的则只屏蔽 1 小时。同时,此脚本不会影响已有的 ipfilter 范围格式屏蔽 (非单 IP 格式),它们会被原样保存。

无法在未提供 `getpeers` API 的旧版本 μTorrent 中正常工作。

**请在本地网络内使用此脚本**,μTorrent 网页 API 不支持 HTTPS 连接,它并不安全。
每 10 秒进行一次检查,屏蔽时间可以由启动参数指定,默认为 12 小时。屏蔽吸血并不是一刀切完全屏蔽,个别会有回传且处于容忍度以内,这时不会马上屏蔽它。这是个反向吸血措施,如果此下载在本机处于做种状态,那么就会马上屏蔽它们,其中判断为恶性吸血的仍然屏蔽 12 小时,无法确定的则只屏蔽 1 小时。同时,此脚本不会影响已有的 ipfilter 范围格式屏蔽 (非单 IP 格式),它们会被原样保存。

给 μTorrent 3 经典桌面版免费版本用户的[一份礼物](https://github.com/SeaHOH/ban-peers/issues/1)

极力抵制吸血,这是我们应有的权利。如果你觉得 Ban-Peers 还不错,请向朋友推荐它,谢谢。

# 注意事项
- 无法在未提供 `getpeers` API 的旧版本 μTorrent 中正常工作。
- **请在本地网络内使用此脚本**,μTorrent 网页 API 不支持 HTTPS 连接,它并不安全。
- 虽然已采取一些预防措施,如果你仍然发现有正常的对端被错误屏蔽,请反馈到 [issues 板块](https://github.com/SeaHOH/ban-peers/issues)

# 安装
安装自
[![version](https://img.shields.io/pypi/v/ban-peers)](https://pypi.org/project/ban-peers/)
Expand Down Expand Up @@ -60,11 +61,11 @@ Android:

```
ban_peers -h
欢迎使用 Ban-Peers 0.1.8
欢迎使用 Ban-Peers 0.1.11
用法:
ban_peers [-H IP|域名] [-p 端口] [-a 用户名:密码] [-e 小时]
[-f 格式] [-C] [-X] [-P] [-L] [-R] [-h] [-v]
[-f 格式] [-C] [-X] [-P] [-L] [-R] [-U] [-h] [-v]
[IP屏蔽配置路径]
通过网页 API 检查并屏蔽 BitTorrent 吸血对端,工作于 uTorrent。
Expand Down Expand Up @@ -94,13 +95,15 @@ ban_peers -h
不进行严重吸血检查
-R, --private-check
启用对私人种子的检查
-U, --log-unknown
将未知客户端记入日志
-h, --help 显示此帮助信息并退出
-v, --version 显示版本信息并退出
```

```markdown
C:\Users\username>ban_peers -p 12345 -a username:password X:\uTorrent
欢迎使用 Ban-Peers 0.1.8
欢迎使用 Ban-Peers 0.1.11
19:44:35 设定 uTorrent 配置 'bt.use_rangeblock' 到 False **_脚本退出后不会自动恢复_**
19:44:35 uTorrent 自动屏蔽脚本开始运行
请选择你要执行的操作: (Q)退出,(S)停止,(R)重新开始,(P)暂停/恢复
Expand All @@ -110,7 +113,7 @@ C:\Users\username>ban_peers -p 12345 -a username:password X:\uTorrent

```markdown
C:\Users\username>ban_peers
欢迎使用 Ban-Peers 0.1.8
欢迎使用 Ban-Peers 0.1.11
请输入 uTorrent 配置文件夹路径,或者 ipfilter 文件路径:
X:\uTorrent
请输入 WebUI 用户名: username
Expand Down
149 changes: 124 additions & 25 deletions ban_peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Checking & banning BitTorrent leech peers via Web API, working for uTorrent.
"""
__app_name__ = 'Ban-Peers'
__version__ = '0.1.10'
__version__ = '0.1.11'
__author__ = 'SeaHOH<[email protected]>'
__license__ = 'MIT'
__copyright__ = '2020 SeaHOH'
Expand Down Expand Up @@ -55,35 +55,123 @@
TOKEN = re.compile('<div id=.token.[^>]*>([^<]+)</div>')
# The PEER CLIENT is not a PeerID or a User-Agent, it's a mixed string
# "-" prefix and suffix were removed by class `List2Attr`
LEECHER_XUNLEI = re.compile('^(?:xl|xun|sd|(?:unknown.+?/)?7\.)', re.I)
LEECHER_PLAYER = re.compile('''
LEECHER_XUNLEI = re.compile('''
^(?:
dan | # DanDan (DL)
sod | # Soda
vag | # Vagaa (VG)
(?:unknown\s)?(?:
dl | # DanDan/DLBT (DL)
uw | # uTorrent Web (UW)
xf # Xfplay (XF)
7\.|sd|xl|xun|
unknown\s(?:
bt/7\.(?!(?:9|10)\.\d\D)|
sd|xl
)
)
''', re.I|re.X)
LEECHER_FAKE = re.compile('''
^(?:unknown )?
(?:fw|frostwire)/\d\.\d\.\d\.\d # Unknown FW/6.8.5.3 -> FrostWire/6.8.5
# see github.com/frostwire/frostwire#921
''', re.I|re.X)
LEECHER_PLAYER = re.compile('''
^(?:
dan | # DanDan (DL)
DLB|dlb | # DLBT (DL)
[Qq]vo | # Qvod (QVOD) [Dead]
[Ss]od | # Soda
[Tt]orc | # Torch (TB)
[Vv]ag | # Vagaa (VG) [Dead?]
[Xx]fp | # Xfplay (XF)
Unknown\s(?:
DL | # DanDan/DLBT (DL)
QVO | # Qvod (QVOD) [Dead]
TB | # Torch (TB)
UW | # uTorrent Web (UW)
VG | # Vagaa (VG) [Dead?]
XF # Xfplay (XF)
)
)
''', re.X)
# Offline Download Servers (does not used at present)
# bitport.io [Unknown ID/UA]
# put.io [Unknown ID/UA]
# justseed.it [Unknown UA] [Dead]
# seedboxws.com [Unknown ID/UA]
# seedr.cc [Unknown ID/UA]
# yourseedbox.com [Unknown ID/UA]
LEECHER_OFFLINE = re.compile('''
^(?:
[Jj]usts | # Justseed.it client [Dead]
Unknown\s(?:
JS # Justseed.it client [Dead]
)
)
''', re.X)
LEECHER_OTHER = re.compile('''
^(?:
caca | # Cacaoweb
flashg | # FlashGet (FG)
tuo | # TuoTu (TT), be careful avoid match tTorrent (tT)
(?:unknown\s)?(?:
bn | # Baidu (BN)
q[qd] # QQ (QD)
caca | # Cacaoweb
[Ff]lash[Gg] | # FlashGet (FG)
.+?ransp | # Net Transport (NX) - need more infomation
[Qq]{2} | # QQ (QD)
[Tt]uo | # TuoTu (TT)
Unknown\s(?:
BN | # Baidu (BN)
FG | # FlashGet (FG)
NX | # Net Transport (NX)
QD | # QQ (QD)
TT # TuoTu (TT)
)
)
''', re.I|re.X)
''', re.X)
# Did not included in uTorrent's peer identification
# https://www.bittorrent.org/beps/bep_0020.html
# https://wiki.theory.org/BitTorrentSpecification
# Most of them has been died
CLIENT_UNKNOWN = re.compile('''
^Unknown\s(?!
\d\dRS | # Rufus [Dead]
7T | # aTorrent for Android
AL | # AllPeers [Dead]
AT | # Artemis [Dead]
BE | # Baretorrent [Dead?]
BitS | # BitSpirit
BL | # BitBlinder [Dead]
# BitCometLite
BOW | # Bits On Wheels [Dead]
BP | # BitTorrent Pro (Azureus + spyware) [Dead?]
BS | # BTSlave [Dead]
Bt | # Bt [library]
#BT | # BBtor [Dead]
BT/7\.(?:9|10)\.\d\D| # mainline BitTorrent [versions >= 7.9]
BW | # BitWombat [Dead]
DP | # Propagate Data Client [Dead]
FC | # FileCroc [Dead]
FD | # Free Download Manager
FW | # FrostWire
FX | # Freebox BitTorrent
GS | # GSTorrent [Dead]
HK | # Hekate [Dead?]
HM | # hMule [Dead]
IL | # iLivid [Dead]
JT | # JavaTorrent
KG | # KGet [Dead]
LC | # LeechCraft
LH | # LH-ABC [Dead]
#M\d-\d | # Bram's old BitTorrent and many other clients [Dead]
ML | # MLdonkey
MK | # Meerkat [Dead]
MO | # MonoTorrent [Dead?]
NE | # BT Next Evolution [Dead?]
OS | # OneSwarm
OT | # OmegaTorrent [Dead]
PD | # Pando [Dead]
PI | # PicoTorrent
PT | # PHPTracker [Dead]
#Q\d-\d | # Queen Bee [Dead]
#Q\d[a-zA-Z0-9]{2}| # BTQueue [Dead]
RZ | # RezTorrent [Dead?]
SB | # ~Swiftbit [Dead]
SM | # SoMud [Dead]
ST | # SymTorrent [Dead]
st | # sharktorrent [Dead]
tT | # tTorrent
WD | # WebTorrent Desktop
WW | # WebTorrent [library]
WY | # FireTorrent [Dead]
XBT # XBT Client [Dead?]
)
''', re.X)


try:
Expand Down Expand Up @@ -230,7 +318,8 @@ def __init__(self,
username:Optional[str]='', password:Optional[str]='',
expire:int=3600*12, log_header_fmt:str='%H:%M:%S',
xunlei_reprieve:bool=True, check_fake_progress:bool=True,
check_serious_leech:bool=True, check_private:bool=False) -> None:
check_serious_leech:bool=True, check_private:bool=False,
log_unknown=False) -> None:
while not ipfilter:
ipfilter = input(LANG_INPUT_IPFILTER)
if os.path.isdir(ipfilter):
Expand All @@ -248,6 +337,7 @@ def __init__(self,
self.check_fake_progress = check_fake_progress
self.check_serious_leech = check_serious_leech
self.check_private = check_private
self.log_unknown = log_unknown
self.log_header_fmt = log_header_fmt
self._params_list = {'list': 1, 'cid': 0, 'getmsg': 1}
self._seeds_private = {}
Expand Down Expand Up @@ -500,8 +590,7 @@ def log(msg):
reasons.append('Player')
elif peer.downloaded == peer.relevance == 0:
reasons.append('Player')
elif peer.client.startswith('[FAKE]') or \
LEECHER_FAKE.search(peer.client):
elif peer.client.startswith('[FAKE]'):
log(LANG_FACK_CLIENT)
if seeding:
reasons.append('Seeding')
Expand Down Expand Up @@ -553,6 +642,8 @@ def log(msg):
self._statistics_uploaded[hash].pop(ip_port, None)
peer.downloaded += _downloaded
peer.uploaded += _uploaded
if self.log_unknown and CLIENT_UNKNOWN.search(peer.client):
log(LANG_UNKNOWN_CLIENT)
if reasons:
if not seeding:
self._statistics_progress.pop(ip_port, None)
Expand Down Expand Up @@ -677,6 +768,7 @@ def log(msg):
LANG_OFFLINE_SERVER = '离线下载服务器'
LANG_LEECHER_CLIENT = '吸血客户端'
LANG_LEECHER_SUSPECTED = '高度疑似吸血'
LANG_UNKNOWN_CLIENT = '未知客户端'
LANG_STATISTICS = '统计'
LANG_DOWNLOADED = '已下载'
LANG_UPLOADED = '已上传'
Expand Down Expand Up @@ -705,6 +797,7 @@ def log(msg):
LANG_HELP_NO_FAKE_PROGRESS_CHECK = '不进行虚假进度检查'
LANG_HELP_NO_SERIOUS_LEECH_CHECK = '不进行严重吸血检查'
LANG_HELP_PRIVATE_CHECK = '启用对私人种子的检查'
LANG_HELP_LOG_UNKNOWN = '将未知客户端记入日志'
__doc__ = '通过网页 API 检查并屏蔽 BitTorrent 吸血对端,工作于 uTorrent。'
else:
LANG_INPUT_IPFILTER = 'Please input uTorrent settings folder path or ipfilter file path:\n'
Expand Down Expand Up @@ -733,6 +826,7 @@ def log(msg):
LANG_OFFLINE_SERVER = 'offline download server'
LANG_LEECHER_CLIENT = 'leecher client'
LANG_LEECHER_SUSPECTED = 'highly suspected of leecher'
LANG_UNKNOWN_CLIENT = 'unknown client'
LANG_STATISTICS = 'Statis'
LANG_DOWNLOADED = 'D'
LANG_UPLOADED = 'U'
Expand Down Expand Up @@ -761,6 +855,7 @@ def log(msg):
LANG_HELP_NO_FAKE_PROGRESS_CHECK = 'Don\'t checking fake progress'
LANG_HELP_NO_SERIOUS_LEECH_CHECK = 'Don\'t checking serious leech'
LANG_HELP_PRIVATE_CHECK = 'Enable checking for private seeds'
LANG_HELP_LOG_UNKNOWN = 'Logging unknown clients'

__doc__ = f'''\
{__app_name__} {__version__}
Expand Down Expand Up @@ -813,6 +908,8 @@ def main() -> None:
help=LANG_HELP_NO_SERIOUS_LEECH_CHECK)
parser.add_argument('-R', '--private-check', action='store_true',
help=LANG_HELP_PRIVATE_CHECK)
parser.add_argument('-U', '--log-unknown', action='store_true',
help=LANG_HELP_LOG_UNKNOWN)
parser.add_argument('-h', '--help', action='store_true',
help=LANG_HELP_HELP)
parser.add_argument('-v', '--version', action='store_true',
Expand Down Expand Up @@ -845,6 +942,8 @@ def main() -> None:
kwargs['check_serious_leech'] = False
if args.private_check:
kwargs['check_private'] = True
if args.log_unknown:
kwargs['log_unknown'] = True
ut = UTorrentWebAPI(args.ipfilter, **kwargs)
if args.resolve_country:
ut.set_setting('peer.resolve_country', True)
Expand Down

0 comments on commit a55ca65

Please sign in to comment.