PT站自动登陆及读取消息脚本

  • 可供一般PT站自动登陆,已保留账号之用。
  • 填写邮箱后可以接受登陆失败的信息和未读消息。
  • 默认读取收件箱和系统收件箱,并标记为已读。
  • 默认邮箱程序为 mailx,请自行配置,否则不要填写邮箱。
  • 严禁作为商业用途,转载至个人网站/个人博客 需注明moeclub.org是作者。

使用方法

  • 以MT为例,将代码中的中文全部替换为自己的信息。
  • 可使用 bash -x shell.sh 进行调试。
  • 支持 MT,CHD,HDTime 等等。
  • MT需要设置 Decrypt=’0′; CHD,HDTime需要设置 Decrypt=’1′;其他站可自行测试。

配置邮箱通知:
参考:在VPS上配置邮件通知

文件下载:

1
wget --no-check-certificate -qO chinese.sh 'https://moeclub.org/attachment/LinuxShell/PT/Login/chinese.sh'

也可参考:一些国外PT站自动登陆脚本
附上完整代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# User Data, You should modify it.
export TheHost='https://tp.m-team.cc'
export Account='username=用户名&password=密码'
export MyeMail='邮箱'
export Decrypt='0'
# Do not modify the following.
export HostUrl="$(echo "${TheHost}" |awk -F '://|/' '{print $2}')"
export dirCookie='/tmp/cookie.txt'
Request(){
URL="${1}"
DATA="${2:-}"
ItRef="${3:-login.php}"
[[ -z "$(echo "${URL}" |grep '://')" ]] && echo "Error! URL incorrect. " && exit 1
[ -n "${Decrypt}" ] && [ "${Decrypt}" -eq '1' ] && [ "${ItRef}" != 'login.php' ] && {
curl -k --silent \
-H 'Host: '${HostUrl}'' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: zh-CN,en-US;q=0.8,zh;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Referer: '${TheHost}'/'${ItRef}'' \
-H 'Connection: keep-alive' \
-b ''${dirCookie}'' \
-c ''${dirCookie}'' \
${DATA} ''${URL}'' |gzip -dc
} || {
curl -k --silent \
-H 'Host: '${HostUrl}'' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: zh-CN,en-US;q=0.8,zh;q=0.5,en;q=0.3' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Referer: '${TheHost}'/'${ItRef}'' \
-H 'Connection: keep-alive' \
-b ''${dirCookie}'' \
-c ''${dirCookie}'' \
${DATA} ''${URL}''
}
}
uMessages(){
export ReceiveBox=''${1:-action=viewmailbox&box=1&unread=yes}''
[[ -z "$(echo "$(Request ''${TheHost}'/usercp.php' '-X GET' 'index.php')" |grep 'messages.php' |grep 'embedded')" ]] && export Unread='0' || export Unread='1'
[ "${Unread}" -eq '1' ] && ReadIt="$(echo "$(Request ''${TheHost}'/messages.php?'${ReceiveBox}'' '-X GET' 'messages.php')" |grep -A1 'unreadpm' |grep 'messages.php?action=viewmessage')"
[ "${Unread}" -eq '1' ] && [ -n "${ReadIt}" ] && [ -n "$(which mailx)" ] && TheMessage="$(echo "$(echo "${ReadIt}" |awk -F '"' '{print $2}')" |head -n 1)" && echo "$(Request ''${TheHost}'/'${TheMessage}'' '-X GET' 'messages.php')" >/dev/null
[ "${Unread}" -eq '1' ] && [ -n "${ReadIt}" ] && [ -n "$(which mailx)" ] && [ -n "${TheMessage}" ] && echo -e "New Message\n\n"$(echo "${ReadIt}" |awk -F '<|>' '{print $5}' |head -n 1)"\n"${TheHost}"/"${TheMessage}"\n" |mailx -s "Notice for ${HostUrl}" "${MyeMail}"
[ "${Unread}" -eq '0' ] || uMessages 'action=viewmailbox&box=-2&unread=yes'
}
Request ''${TheHost}'/takelogin.php' '-X POST -d '${Account}'' >/dev/null
[[ -n "$(echo "$(Request ''${TheHost}'/usercp.php' '-X GET' 'index.php')" |grep 'logout.php')" ]] && Login='1' || Login='0'
[[ "${Login}" -eq '1' ]] && {
echo -e "#${HostUrl}#\nLogin Success! "
[ -n "${MyeMail}" ] && uMessages;
rm -rf "${dirCookie}";
exit 0
} || {
[ -n "${MyeMail}" ] && [ -n "$(which mailx)" ] && echo -e "$(date "+%F [%T]")\nLogin Fail! " |mailx -s "Notice for ${HostUrl}" "${MyeMail}"
echo -e "#${HostUrl}#\nLogin Fail! " && rm -rf "${dirCookie}";
exit 1
}