Python Spark
Python Spark

Reputation: 303

Paramiko ssh exec_command for IPv6 server from windows client

The following code is working fine to get output of command execution on remote server for IPv4 using paramiko.SSHClient. But the same code is not working for IPv6 server.

import paramiko
dssh = paramiko.SSHClient()
dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
dssh.connect("IPv6_Address", username="root", password="orange")
stdin,stdout,stderr=dssh.exec_command("pwd")
print(stdout.read())

and then I tried to use socket connection for IPv6 like below

sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.connect((hostname, port))
t = paramiko.Transport(sock)

but paramiko.Transport has no exec_command.

Upvotes: 1

Views: 826

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202642

SSHClient.connect has sock parameter:

sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.connect(("IPv6_Address", port))
dssh.connect("IPv6_Address", username="root", password="orange", sock=sock)

Side note: Do not use AutoAddPolicy like that. You lose security by doing so.
See Paramiko "Unknown Server"
.

Upvotes: 1

Related Questions