Đăng nhập vào Multilogin tự động
Việc kết nối với Multilogin từ nhiều thiết bị hoặc máy chủ theo cách thủ công có thể tốn thời gian. Để tự động hóa quá trình này, bạn có thể sử dụng thư viện Paramiko bằng Python.
Trong bài viết này, bạn sẽ tìm hiểu cách thực hiện việc này bằng cách sử dụng ví dụ về tập lệnh của chúng tôi. Nó lặp qua danh sách các máy chủ, mỗi máy chủ có thông tin xác thực riêng và thực thi các lệnh kết nối.
Trước khi bạn bắt đầu
- Đảm bảo thiết bị hoặc máy chủ của bạn có thể truy cập được qua SSH bằng xác thực mật khẩu
- Cài đặt Python và các thư viện bên dưới trên mỗi thiết bị hoặc máy chủ:
- requests
- paramiko
- Lưu tập lệnh
auto.py
trên thiết bị cục bộ của bạn - Lưu tập lệnh
signinmlx.py
trên các thiết bị hoặc máy chủ bổ sung - Chèn giá trị của bạn vào các biến bên dưới trong tập lệnh
signinmlx.py
:-
USERNAME
: email tài khoản Multilogin X của bạn -
PASSWORD
: mật khẩu tài khoản Multilogin X của bạn ( không cần mã hóa MD5)
-
- Chèn giá trị của bạn vào các biến bên dưới trong tập lệnh
auto.py
:SERVER-USERNAME
SERVER-PASSWORD
SERVER-IP
Chạy tập lệnh
Các ví dụ về tập lệnh bên dưới chứa thiết lập cơ bản cho phép bạn đăng nhập vào tài khoản Multilogin X của mình trên một số máy chủ. Ngoài ra, bạn có thể:
- Thêm hành động hồ sơ mà bạn muốn kích hoạt sau khi đăng nhập bằng
signinmlx.py
- Thêm các lệnh khác bạn muốn thực thi trên máy chủ từ xa bằng
auto.py
- Thêm nhiều máy chủ hơn vào tham số “users_credentials_and_ips” bằng
auto.py
signinmlx.py
import requests
from hashlib import md5
# Input your Multilogin X account credentials
USERNAME = ""
PASSWORD = ""
MLX_BASE = "https://api.multilogin.com"
MLX_LAUNCHER = "https://launcher.mlx.yt:45001/api/v1"
HEADERS = {"Accept": "application/json", "Content-Type": "application/json"}
# Function
def sign_in(username, password):
# HTTP requests to APIs
sign_url = "https://api.multilogin.com/user/signin"
HEADERS = {
"Accept": "application/json",
"Content-Type": "application/json",
}
Payload = {
"email": username,
"password": str(md5(password.encode()).hexdigest()),
}
# POST request
resp = requests.post(sign_url, json=Payload, headers=HEADERS)
resp_json = resp.json()
# got bearer token
token = resp_json["data"]["token"]
return token
# PART 1
token = sign_in(USERNAME, PASSWORD)
HEADERS["Authorization"] = "Bearer " + token
print("token: " + token, end="")
auto.py
import paramiko
# Define the commands to run
commands = [
# "mlx &",
"python3 signinmlx.py"
]
# Define the list of users, passwords, and their corresponding IPs
users_credentials_and_ips = [
# ("SERVER-USERNAME", "SERVER-PASSWORD", "SERVER-IP"),
("SERVER-USERNAME", "SERVER-PASSWORD", "SERVER-IP"),
]
# Iterate over each user, password, and IP
for user, password, ip in users_credentials_and_ips:
print(f"Connecting to {user}@{ip}")
try:
# Connect to the SSH server with password authentication
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip, username=user, password=password)
# Execute each command
for cmd in commands:
print(f"Running command: {cmd}")
stdin, stdout, stderr = ssh_client.exec_command(cmd)
output = stdout.read().decode("utf-8")
error = stderr.read().decode("utf-8")
if output:
print(output)
if error:
print(error)
# Close the SSH connection
ssh_client.close()
except Exception as e:
print(f"Error connecting to {user}@{ip}: {str(e)}")
Video hướng dẫn
Trong hướng dẫn này, chúng tôi trình bày cách chạy tập lệnh auto.py
và signinmlx.py
trên máy cục bộ với Windows 10 và máy chủ VirtualBox với Ubuntu 20.