3

I am trying to connect to Avaya Media server using Paramiko module. It connects when I dont specify a port.But I want it to mimick the behaviour of Avaya Site Administration/Putty using port 5022. Can someone please help me with the code

import paramiko
import time
import os
import sys
time.sleep(1)

ip = "10.xx.xx.xx"
host = ip
username = "admin"
password = "xxxxxxxx"

ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,username=username,password=password)
channel=ssh.invoke_shell()
channel.send("vt100 \n")
time.sleep(5)
output=channel.recv(9999)
print output
channel.send("almdisplay \n")
time.sleep(5)
output=channel.recv(9999)
print output

This code works. But how can code it to use Port 5022?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Richaa Dhar
  • 51
  • 1
  • 2
  • 1
    Maybe `ssh.connect(..., port=5022, ...)`? See [paramiko API documentation](https://docs.paramiko.org/en/2.6/api/client.html) – Stefan Becker Aug 28 '19 at 04:59

1 Answers1

4

You can give the port argument, example as below for port 23:

import paramiko
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname='10.0.1.1', username='test',password='tester', port=23)
stdin,stdout,stderr=ssh_client.exec_command('ls')
output = stdout.readlines()
for items in output:
    print(items)
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Rohan
  • 41
  • 3
  • Correct. Just, please do not use `AutoAddPolicy`. You lose security by doing to. For a correct solution, see [Paramiko “Unknown Server”](https://stackoverflow.com/q/10670217/850848#43093883). – Martin Prikryl Apr 14 '20 at 05:22