前几天github 删除了很多hostloc的签到脚本,看来github actions小气起来,什么事情都能做出来。既然这样,还是使用自己的vps来部署比较稳妥,这篇文章就来说说如何部署。
1、准备
1)宝塔面板或者aapanel
2)需要python3,建议使用宝塔的试验脚本安装。
2、部署1
1)宝塔找个文件目录,比如这里放在opt目录,那么就进入opt目录新建一个mjj.py的文件,然后双击编辑,输入如下代码(支持多账号,注意修改自己的账号和密码。)
#!/usr/bin/env python # -*- coding: UTF-8 -*- # Author: MoeClub.org import re import sys import time from urllib import request, parse from http import cookiejar account_dict = { '0': {'username': '账号A', 'password': '密码A'}, '1': {'username': '账户B', 'password': '密码B'}, } def Login(URL, UserData): _cookies = '' _cookie = cookiejar.CookieJar() _handler = request.HTTPCookieProcessor(_cookie) _req = request.Request(URL, data=parse.urlencode(UserData).encode('utf-8')) request.build_opener(_handler).open(_req) for cookie in _cookie: _cookies += cookie.name + '=' + cookie.value + ';' return _cookies def GetPage(URL, Header_Cookies): _Header = {'Cookie': str(Header_Cookies)} _req = request.Request(URL, headers=_Header) return request.urlopen(_req).read().decode('utf-8') def GetCredit(user_data, proto='https'): username = user_data['username'] Login_URL = proto + '://hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1' My_Credit = proto + '://hostloc.com/home.php?mod=spacecp&ac=credit&showcredit=1&inajax=1' My_Home = proto + '://hostloc.com/home.php?mod=spacecp&inajax=1' My_Cookies = Login(Login_URL, user_data) if '<td>' + str(username) + '</td>' not in GetPage(My_Home, My_Cookies): print('[%s] Login Fail!' % username) else: try: CreditNum0 = str(re.findall('[0-9]+', GetPage(My_Credit, My_Cookies))[-1]) except: CreditNum0 = 'Null' for x in range(25297, 25309): GetPage(proto + '://hostloc.com/space-uid-{}.html'.format(x), My_Cookies) time.sleep(4) try: if CreditNum0 == 'Null': raise Exception CreditNum1 = str(re.findall('[0-9]+', GetPage(My_Credit, My_Cookies))[-1]) if CreditNum0 == CreditNum1: CreditDetails = str(CreditNum1) else: CreditDetails = str(CreditNum0) + '->' + str(CreditNum1) except: CreditDetails = 'Null' print('[%s] Login Success! (Credit: %s)' % (username, CreditDetails)) if __name__ == '__main__': if len(sys.argv) > 1: n = 0 account_dict = {} account_list = [sys.argv[x] for x in range(1, len(sys.argv))] for account in account_list: if ":" not in account: continue account_dict[str(n)] = {} account_dict[str(n)]['username'] = str(str(account).split(":", 1)[0]) account_dict[str(n)]['password'] = str(str(account).split(":", 1)[-1]) n += 1 for i in range(0, len(account_dict)): try: GetCredit(account_dict[str(i)]) time.sleep(4) except: continue
2)用宝塔的自动计划任务来自动定时运行这个脚本
注意:
尽量将自动签到时间设定到半夜,白天论坛的CC防御规则严格,会使签到失败,设置在半夜就没问题了;
脚本内容:(宝塔的实验版本默认是py3.7.9,所以不需要另外安装了,我们直接用btpython即可执行脚本命令。)
cd /opt btpython ./mjj.py
3)执行效果
以上就算是部署好了loc的自动签到脚本。下面在介绍一个别的脚本。继续往下看。
3、部署2
如果你不喜欢上面的py脚本,那么还可以试试这个,
1)第一步下载下列仓库的hostloc_auto_get_points.py文件,https://github.com/Jox2018/hostloc_getPoints,还是在opt目录新建一个比如说mjj.py的文件,博主这里贴一下代码。把下面的代码复制粘贴到你的mjj.py文件中,保存。
import os import time import random import re import textwrap import requests from pyaes import AESModeOfOperationCBC from requests import Session as req_Session # 随机生成用户空间链接 def randomly_gen_uspace_url() -> list: url_list = [] # 访问小黑屋用户空间不会获得积分、生成的随机数可能会重复,这里多生成两个链接用作冗余 for i in range(12): uid = random.randint(10000, 50000) url = "https://hostloc.com/space-uid-{}.html".format(str(uid)) url_list.append(url) return url_list # 使用Python实现防CC验证页面中JS写的的toNumbers函数 def toNumbers(secret: str) -> list: text = [] for value in textwrap.wrap(secret, 2): text.append(int(value, 16)) return text # 不带Cookies访问论坛首页,检查是否开启了防CC机制,将开启状态、AES计算所需的参数全部放在一个字典中返回 def check_anti_cc() -> dict: result_dict = {} headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" } home_page = "https://hostloc.com/forum.php" res = requests.get(home_page, headers=headers) aes_keys = re.findall('toNumbers\("(.*?)"\)', res.text) cookie_name = re.findall('cookie="(.*?)="', res.text) if len(aes_keys) != 0: # 开启了防CC机制 print("检测到防 CC 机制开启!") if len(aes_keys) != 3 or len(cookie_name) != 1: # 正则表达式匹配到了参数,但是参数个数不对(不正常的情况) result_dict["ok"] = 0 else: # 匹配正常时将参数存到result_dict中 result_dict["ok"] = 1 result_dict["cookie_name"] = cookie_name[0] result_dict["a"] = aes_keys[0] result_dict["b"] = aes_keys[1] result_dict["c"] = aes_keys[2] else: pass return result_dict # 在开启了防CC机制时使用获取到的数据进行AES解密计算生成一条Cookie(未开启防CC机制时返回空Cookies) def gen_anti_cc_cookies() -> dict: cookies = {} anti_cc_status = check_anti_cc() if anti_cc_status: # 不为空,代表开启了防CC机制 if anti_cc_status["ok"] == 0: print("防 CC 验证过程所需参数不符合要求,页面可能存在错误!") else: # 使用获取到的三个值进行AES Cipher-Block Chaining解密计算以生成特定的Cookie值用于通过防CC验证 print("自动模拟计尝试通过防 CC 验证") a = bytes(toNumbers(anti_cc_status["a"])) b = bytes(toNumbers(anti_cc_status["b"])) c = bytes(toNumbers(anti_cc_status["c"])) cbc_mode = AESModeOfOperationCBC(a, b) result = cbc_mode.decrypt(c) name = anti_cc_status["cookie_name"] cookies[name] = result.hex() else: pass return cookies # 登录帐户 def login(username: str, password: str) -> req_Session: headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", "origin": "https://hostloc.com", "referer": "https://hostloc.com/forum.php", } login_url = "https://hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1" login_data = { "fastloginfield": "username", "username": username, "password": password, "quickforward": "yes", "handlekey": "ls", } s = req_Session() s.headers.update(headers) s.cookies.update(gen_anti_cc_cookies()) res = s.post(url=login_url, data=login_data) res.raise_for_status() return s # 通过抓取用户设置页面的标题检查是否登录成功 def check_login_status(s: req_Session, number_c: int) -> bool: test_url = "https://hostloc.com/home.php?mod=spacecp" res = s.get(test_url) res.raise_for_status() res.encoding = "utf-8" test_title = re.findall("
2)还是和上面一样用计划任务来定时运行这个脚本。
cd /opt btpython ./mjj.py
3)这个脚本如果提示以下错误,请安装request模块。
Traceback (most recent call last): File "/root/hostloc/hostloc_auto_get_points.py", line 6, in ...
安装request模块,代码如下:
pip3 install requests
4、最后
用自己的vps来部署这个还是很方便的,宝塔的实验版本是自带python3的,但是做软连接的时候被改名为btpython所以这里需要注意下。
参考:
https://github.com/Jox2018/hostloc_getPoints
https://sunpma.com/612.html
未经允许不得转载:mis笔记 » 宝塔面板部署hostloc签到脚本
最新评论
过来学习!
试试评论~~
这是第一个评论测试~