Python Api to Reboot Antminer

September 30, 2018

Cgiminer Api has a restart command, but it require configuration to allow the priviledged command, and I doubt it restart the entire machine.

Instead, I opt to write code to SSH into the machine and issue a reboot command. The downside is root/admin username and password is required.

I use Paramiko for Python SSH support.

import paramiko

def reboot(ip):
  ssh = paramiko.SSHClient()
  # paramiko.ssh_exception.SSHException: Server '192.168.1.1' not found in known_hosts
  ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  ssh.connect(ip, username='root', password='password')
  # ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("ls -a")
  ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("/sbin/reboot")
  # print ssh_stdin.readlines()
  print ssh_stdout.readlines()
  print ssh_stderr.readlines()
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.