How to log in to Multilogin with Python
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.
If you are not sure where to start with the running and editing the script – you can refer to the first 4 steps of the following article: Getting started with automation scripting.
Before you start
- Ensure your devices or servers are accessible via SSH with password authentication
The SSH command for connecting to the device/server:
ssh user@exampleIPFor Windows, you have to install OpenSSH Client feature or PuTTy.
- Install Python and libraries below on each device or server:
- requests
- paramiko
For PC or server, where you try to connect your script, you will have to install it via terminal or similar tool.
Consider using the following commands there for installing Python and modules:
python3pip install requestspip install paramiko
- Save the script
auto.pyon your local device - Save the script
signinmlx.pyon additional devices or serversMake sure to put the script in the root or home (in case of Linux) folder of the PC, which you are going to connect.
- 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-USERNAMESERVER-PASSWORDSERVER-IP
You will receive a token, which can be used for various actions in API (the result is similar to Sign In API request).
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.
This article includes third-party links that we don’t officially endorse.