lightsail
是亚马逊云科技出品的类似轻量服务器的产品,不过比国内这些平台的价格划算,带宽很高,可以用来做很多事情。这次介绍一下如何利用lightsail
搭建电报自动签到系统~
使用前可以先注册一个亚马逊云科技的账号,可以免费使用3
个月~~
1、创建lightsail实例
打开链接:Lightsail (amazon.com),然后点击创建实例:
这里我们选择Ubuntu22.04 LTS
版本就行,纯系统
就可以,不需要附带其他APP
:
注意提前把默认的key
下载下来:
然后我们可以选择一个合适的套餐,这里我以5美元/月
的举例:
最后随便写个名字,创建实例即可~
接下来稍等片刻,新的实例就创建好了~
打开本地终端,登陆实例:
ssh ubuntu@57.180.12.217 -i LightsailDefaultKey-ap-northeast-1.pem
有可能会报错:
1 2 3 4 5 6 7 8 9 |
$ ssh ubuntu@57.180.12.217 -i LightsailDefaultKey-ap-northeast-1.pem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for 'LightsailDefaultKey-ap-northeast-1.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "LightsailDefaultKey-ap-northeast-1.pem": bad permissions ubuntu@57.180.12.217: Permission denied (publickey). |
无妨,这是因为权限太低导致的,我们可以更改key的权限:
chmod 600 LightsailDefaultKey-ap-northeast-1.pem
到这里,实例的创建就完成了,接下来安装Python
的运行环境
2、Python运行环境
默认是安装了Python3
的,不过pip3
没有安装,我们手动装一下
sudo apt update
sudo apt install python3-pip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
ubuntu@ip-172-26-4-98:~$ sudo apt install python3-pip Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: build-essential bzip2 cpp cpp-11 dpkg-dev fakeroot fontconfig-config fonts-dejavu-core g++ g++-11 gcc gcc-11 gcc-11-base javascript-common libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6 libatomic1 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libdeflate0 libdpkg-perl libexpat1 libexpat1-dev libfakeroot libfile-fcntllock-perl libfontconfig1 libgcc-11-dev libgd3 libgomp1 libisl23 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libjs-jquery libjs-sphinxdoc libjs-underscore liblsan0 libmpc3 libnsl-dev libpython3-dev libpython3-stdlib libpython3.10 libpython3.10-dev libpython3.10-minimal libpython3.10-stdlib libquadmath0 libstdc++-11-dev libtiff5 libtirpc-dev libtsan0 libubsan1 libwebp7 libxpm4 linux-libc-dev lto-disabled-list make manpages-dev python3 python3-dev python3-minimal python3-wheel python3.10 python3.10-dev python3.10-minimal rpcsvc-proto zlib1g-dev Suggested packages: bzip2-doc cpp-doc gcc-11-locales debian-keyring g++-multilib g++-11-multilib gcc-11-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-11-multilib apache2 | lighttpd | httpd glibc-doc bzr libgd-tools libstdc++-11-doc make-doc python3-doc python3-tk python3-venv python3.10-venv python3.10-doc binfmt-support The following NEW packages will be installed: build-essential bzip2 cpp cpp-11 dpkg-dev fakeroot fontconfig-config fonts-dejavu-core g++ g++-11 gcc gcc-11 gcc-11-base javascript-common libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6 libatomic1 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libdeflate0 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libfontconfig1 libgcc-11-dev libgd3 libgomp1 libisl23 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libjs-jquery libjs-sphinxdoc libjs-underscore liblsan0 libmpc3 libnsl-dev libpython3-dev libpython3.10-dev libquadmath0 libstdc++-11-dev libtiff5 libtirpc-dev libtsan0 libubsan1 libwebp7 libxpm4 linux-libc-dev lto-disabled-list make manpages-dev python3-dev python3-pip python3-wheel python3.10-dev rpcsvc-proto zlib1g-dev The following packages will be upgraded: libexpat1 libpython3-stdlib libpython3.10 libpython3.10-minimal libpython3.10-stdlib python3 python3-minimal python3.10 python3.10-minimal 9 upgraded, 64 newly installed, 0 to remove and 71 not upgraded. Need to get 78.8 MB of archives. After this operation, 239 MB of additional disk space will be used. Do you want to continue? [Y/n] y |
当然, 中间可能会有提示,不用管,默认OK
即可:
接下来,我们安装一个必要的包:telethon
pip3 install telethon
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 |
ubuntu@ip-172-26-4-98:~$ pip3 install telethon Defaulting to user installation because normal site-packages is not writeable Collecting telethon Downloading Telethon-1.37.0.tar.gz (620 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 620.2/620.2 KB 13.3 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Collecting rsa Downloading rsa-4.9-py3-none-any.whl (34 kB) Collecting pyaes Downloading pyaes-1.6.1.tar.gz (28 kB) Preparing metadata (setup.py) ... done Requirement already satisfied: pyasn1>=0.1.3 in /usr/lib/python3/dist-packages (from rsa->telethon) (0.4.8) Building wheels for collected packages: telethon, pyaes Building wheel for telethon (pyproject.toml) ... done Created wheel for telethon: filename=Telethon-1.37.0-py3-none-any.whl size=694380 sha256=1ba2c5854264adac12d77ee87b49b736cccfad3e46494e4bdc2a496d697b4fba Stored in directory: /home/ubuntu/.cache/pip/wheels/8b/3c/0a/91d35499092d78120d71039a156b5c450f3ca00f95b4d594a4 Building wheel for pyaes (setup.py) ... done Created wheel for pyaes: filename=pyaes-1.6.1-py3-none-any.whl size=26363 sha256=169253b7b2fe4e636e4c990b40c2ca0fb813177a0ff9cf354cfda15bf29fdd6a Stored in directory: /home/ubuntu/.cache/pip/wheels/d6/84/5f/ea6aef85a93c7e1922486369874f4740a5642d261e09c59140 Successfully built telethon pyaes Installing collected packages: pyaes, rsa, telethon WARNING: The scripts pyrsa-decrypt, pyrsa-encrypt, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/home/ubuntu/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pyaes-1.6.1 rsa-4.9 telethon-1.37.0 |
3、自动签到脚本
在进一步签到之前,我们需要获取电报的API_ID
和HASH
,点击链接进行申请即可,这一点不多说。
拿到API_ID
和HASH
之后,在服务器新建一个Python
文件,填入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# -*- coding: utf-8 -*- import os import time from telethon import TelegramClient, events, sync api_id = [xxx] #输入api_id,一个账号一项 api_hash = ['xxx'] #输入api_hash,一个账号一项 session_name = api_id[:] for num in range(len(api_id)): session_name[num] = "id_" + str(session_name[num]) client = TelegramClient(session_name[num], api_id[num], api_hash[num]) client.start() client.send_message("@xxxxx", '签到') #第一项是机器人ID,第二项是发送的文字 time.sleep(5) #延时5秒,等待机器人回应(一般是秒回应,但也有发生阻塞的可能) client.send_read_acknowledge("@xxxxx") #将机器人回应设为已读 print("Done! Session name:", session_name[num]) os._exit(0) |
注意将里面的必要信息改成自己的。
最后运行:python3 xx.py
即可
当然,亚马逊云科技不光这些可以用,还有很多免费的,大家可以去瞅瞅,地址:亚马逊云科技。