Richaa Dhar
Richaa Dhar

Reputation: 71

How to specify port number with Paramiko

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?

Upvotes: 5

Views: 13262

Answers (1)

Rohan
Rohan

Reputation: 51

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)

Upvotes: 5

Related Questions