利用python+crontab定时任务,实现ikuuu账户(vpn)自动签到

一、思路

1、创建python脚本,调用对应https接口,实现登录、签到功能;
2、创建crontab定时任务,定时执行python签到脚本。

二、实现

1、python脚本

创建一个脚本ikuuuCheckIn.py,内容为:

#!/usr/bin/python
#coding=UTF-8
__author__ = 'huangsan'
import requests
import datetime
#修改默认encoding方式,解决Python中的UnicodeEncodeError编码错误问题
import sys
reload (sys)
sys.setdefaultencoding('utf-8')

def main():
    #打印当前时间
    print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    # 需要签到的账号
    accountList = ['userName@163.com&userPwd']
    print("共需要签到" + str(len(accountList)) + "个账号")
    i = 1
    for account in accountList:
        print("=====正在执行第" + str(i) + "个账号=====")
        email = account.split('&')[0]
        passwd = account.split('&')[1]
        sign_in(email, passwd)
        print("=====第" + str(i) + "个账号,执行完毕=====")
        i += 1
def sign_in(email, passwd):
    # 请求头
    headers = {'Accept':'application/json, text/javascript, */*; q=0.01','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8','user-agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'}
    # 请求参数
    body = {"email" : email,"passwd" : passwd,}
    # session
    httpSession = requests.session()
    try:
        # 登录
        print("登录")
        loginResp = httpSession.post('https://ikuuu.art/auth/login', headers=headers, data=body)
        print("loginResp=" + loginResp.text.decode("unicode_escape"))
        if 1 != loginResp.json()['ret'] :
            print("登录失败,请检查帐号配置是否错误:email=" + email + ", passwd=" + passwd)
            return
    except Exception as e:
        # 登录异常,记录信息
        raise Exception("登录异常:email=" + str(email) + ", passwd=" + passwd + ", e:" + repr(e))
    print("登录成功")
    try:
        # 签到
        print("签到")
        checkinResp = httpSession.post('https://ikuuu.art/user/checkin')
        print("checkinResp=" + checkinResp.text.decode("unicode_escape"))
        if 1 != checkinResp.json()['ret'] :
            print("签到失败:email=" + email + ", passwd=" + passwd)
            return
    except Exception as e:
        # 签到异常,记录信息
        print("签到异常:email=" + email + ", passwd=" + passwd + ", e:" + repr(e))
    print("签到成功")
# 入口
if __name__ == '__main__':
    main()

2、crontab任务

以Linux为例:
通过crontab -l可查看当前所有定时任务。
通过crontab -e可添加新的定时任务:

30 0 * * * /root/temp/pyTest/ikuuuCheckIn.py >> /root/temp/pyTest/ikuuuCheckIn.log_u_$(date -u +"\%Y\%m").log 2>&1

每天0点30分执行一次,执行输出日志追加至对应文件。

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于 OpenVPN 的使用教程,基本上可以分为两个部分,一是安装配置 OpenVPN 服务端,二是安装配置 OpenVPN 客户端。下面是简单的步骤: 1. 安装 OpenVPN 服务端 (1) 在 Linux 系统中,可以使用命令行下载安装 OpenVPN: sudo apt-get update sudo apt-get install openvpn (2) 下载 OpenVPN 安装程序并按照提示安装。 2. 配置 OpenVPN 服务端 (1) 生成 CA 和服务器证书和密钥: cd /etc/openvpn/easy-rsa source vars ./clean-all ./build-ca ./build-key-server server ./build-dh (2) 配置 OpenVPN: sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf /etc/openvpn/ sudo vi /etc/openvpn/server.conf 修改以下参数: secret ta.key cipher AES-128-CBC auth SHA256 user nobody group nogroup push "redirect-gateway def1 bypass-dhcp" (3) 配置虚拟网络: sudo vi /etc/sysctl.conf 将以下行取消注释并保存: net.ipv4.ip_forward=1 使配置生效: sudo sysctl -p (4) 配置防火墙: sudo ufw allow 1194/udp (5) 重启服务: sudo systemctl restart openvpn 3. 安装 OpenVPN 客户端 (1) 在 Windows 上,可以下载 OpenVPN Connect 并按照提示安装。 (2) 在 Linux 上,可以使用命令行下载安装 OpenVPN: sudo apt-get update sudo apt-get install openvpn 4. 配置 OpenVPN 客户端 (1) 下载客户端证书和密钥: scp user@<server_ip>:/etc/openvpn/easy-rsa/keys/client.crt ~/ scp user@<server_ip>:/etc/openvpn/easy-rsa/keys/client.key ~/ scp user@<server_ip>:/etc/openvpn/ta.key ~/ (2) 在 Windows 上,打开 OpenVPN Connect 并导入证书和密钥。 (3) 在 Linux 上,可以使用命令行连接 OpenVPN: sudo openvpn --config /path/to/client.ovpn 其中 client.ovpn 需要根据实际情况进行修改。 以上就是使用 OpenVPN 的基本步骤,希望对您有帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值