问题
I have to write a script that executes some commands on a remote machine using SSH. I had used paramiko for this and everything worked as long as I used IPv4 addressing. I had to switch IPv6 addressing and I can't seem to get Paramiko client to connect.
import paramiko
s = paramiko.SSHClient()
ip6_addr = 'fe80::1112:bcde:789a:1234'
s.connect (ip6_addr, username='foo', password='bar')
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 290, in connect
sock.connect(addr)
File "<string>", line 1, in connect
socket.error: [Errno 22] Invalid argument
Is there an example on how to specify the ip6 address to paramiko?
回答1:
You have to specify the interface name as well.
ip6_addr = 'fe80::1112:bcde:789a:1234%<interface>'
Following example is valid IPv6:
ip6_addr = 'fe80::1112:bcde:789a:1234%eth0'
回答2:
On my Python2.7.9 (which is also not the latest) and paramiko-1.15.2, I have no Problems.
Have you tried upgrading paramiko?
pip install --upgrade paramiko
EDIT: Another idea, maybe your kernel does not support ipv6. How to test from userspace if the kernel supports IPv6?
来源:https://stackoverflow.com/questions/31956313/python-paramiko-and-ipv6-ssh