简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM