1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Paramiko, Python, Windows : How to connect to a remote computer and from there to a...

Discussão em 'Python' iniciado por Stack, Abril 1, 2025.

  1. Stack

    Stack Membro Participativo

    I've seen several questions and answers related to this topic but I've been unable to grasp the howto.


    1. What I'm able to do : connect to a remote computer using a Python script using Paramiko and return information, for instance, to ping a switch :


      ssh = pk.SSHClient()

      ssh.set_missing_host_key_policy(pk.AutoAddPolicy())

      ssh.connect('{}'.format(IP), port=xxx, username='xxx',password='xxx')

      stdin, stdout, stderr = \

      ssh.exec_command('ping -n 1 xxx.xxx.x.x\n')

      print('Ping switch: \n', stdout.readlines())
      ​

    2. What I would like to do but don't know how to : connect once to the computer and then using SSH (paramiko.SSHClient()) again connect to another device (in this case a NAS) and 'exec_command', something like :


      ssh = pk.SSHClient()

      ssh.set_missing_host_key_policy(pk.AutoAddPolicy())

      ssh.connect('{}'.format(IP), port=xxx, username='xxx',password='xxx') # connect to computer

      ssh.connect('{}'.format(IP), port=xxx, username='xxx',password='xxx') #connect to NAS from computer

      stdin, stdout, stderr = \

      ssh.exec_command('shutdown\n, y\n') # send command to NAS

      print('Ping switch: \n', stdout.readlines())
      ​

    [​IMG]

    Is this possible, does anyone know a way?

    Thank you in advance.

    Continue reading...

Compartilhe esta Página