Logging in to Multilogin automatically
Connecting to Multilogin from multiple devices or servers manually can be time-consuming. To automate this process, you can use the Paramiko library in Python.
In this article, you will learn how to do this using our script example. It iterates through a list of servers, each with its own credentials, and executes connection commands.
Before you start
- Ensure your devices or servers are accessible via SSH with password authentication
- Install Python and libraries below on each device or server:
- requests
- paramiko
- Save the script
auto.py
on your local device - Save the script
signinmlx.py
on additional devices or servers - Insert your values into the below variables in the script
signinmlx.py
:-
USERNAME
: your Multilogin X account email -
PASSWORD
: your Multilogin X account password (MD5 encryption is not required)
-
- Insert your values into the below variables in the script
auto.py
:SERVER-USERNAME
SERVER-PASSWORD
SERVER-IP
Running the script
The script examples below contain basic setup that allows you to log in to your Multilogin X account on several servers. Additionally, you can:
- Add profile actions you want to trigger after sign in using
signinmlx.py
- Add more commands you want to execute on remote servers using
auto.py
- Add more servers to the parameter “users_credentials_and_ips” using
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 guide
In this guide, we show how to run the auto.py
and signinmlx.py
scripts on a local machine with Windows 10 and a VirtualBox server with Ubuntu 20.