Using ssh to remotely execute command Python -


i'm new python , cannot solve reason code not working . i'm trying connect several servers hostname list on file via ssh(using paramiko).

something weird happens,the code working if there 1 hostname in file, if has more that, not working . clear loop working fine.

hope can assist me, in advance !

the code:

import sys import os import paramiko  client=paramiko.sshclient() client.set_missing_host_key_policy(paramiko.autoaddpolicy())  username='yadayada' password='ladida' ipfile=open("c:\users\garmiza\documents\scripts\traptohpsimlinuxiplist.txt","r")   line in iter(ipfile):    print "sending trap " + line    client.connect(line,username=username,password=password)    command="snmptrap -v 1 -c public 16.19.203.96 enterprises.232 {clientip} 6 11003 0".format(clientip=line)    stdin, stdout, stderr = client.exec_command(command)   ipfile.close() 

the errors:

  file "c:/users/zaza/pycharmprojects/linuxtrapsending/linuxtrapsending.py", line 16, in <module>      client.connect(line,username=username,password=password)   file "c:\python27\lib\site-packages\paramiko\client.py", line 301, in connect     to_try = list(self._families_and_addresses(hostname, port))   file "c:\python27\lib\site-packages\paramiko\client.py", line 199, in _families_and_addresses     hostname, port, socket.af_unspec, socket.sock_stream) socket.gaierror: [errno 11001] getaddrinfo failed  process finished exit code 1 

according msdn documentation:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx

the getaddrinfo function provides protocol-independent translation ansi host name address.

and error code 11001:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx#wsahost_not_found

host not found. no such host known. name not official host name or alias, or cannot found in database(s) being queried. error may returned protocol , service queries, , means specified name not found in relevant database.

you must passing wrong hostname (or host doesn't exist).


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -