本文整理汇总了Python中paramiko.WarningPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python paramiko.WarningPolicy方法的具体用法?Python paramiko.WarningPolicy怎么用?Python paramiko.WarningPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko
的用法示例。
在下文中一共展示了paramiko.WarningPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _try_passwordless_paramiko
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _try_passwordless_paramiko(server, keyfile):
"""Try passwordless login with paramiko."""
if paramiko is None:
msg = "Paramiko unavailable, "
if sys.platform == 'win32':
msg += "Paramiko is required for ssh tunneled connections on Windows."
else:
msg += "use OpenSSH."
raise ImportError(msg)
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True)
except paramiko.AuthenticationException:
return False
else:
client.close()
return True
示例2: _try_passwordless_paramiko
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _try_passwordless_paramiko(server, keyfile):
"""Try passwordless login with paramiko."""
if paramiko is None:
msg = "Paramiko unavaliable, "
if sys.platform == 'win32':
msg += "Paramiko is required for ssh tunneled connections on Windows."
else:
msg += "use OpenSSH."
raise ImportError(msg)
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True)
except paramiko.AuthenticationException:
return False
else:
client.close()
return True
示例3: ssh_into_device
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def ssh_into_device(lport, interactive, decryption_type, full_reversing):
print "[+] SSH'ing into device"
try:
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy)
ssh_client.connect('localhost', port=lport, username='root', password=root_password)
if interactive:
interactive_shell()
else:
decrypt_application(decryption_type, lport, full_reversing)
except Exception as e:
print "[-] SSH error: ", e
cleanup()
sys.exit()
finally:
cleanup()
示例4: _try_passwordless_paramiko
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _try_passwordless_paramiko(server, keyfile):
"""Try passwordless login with paramiko."""
if paramiko is None:
msg = "Paramiko unavaliable, "
if sys.platform == 'win32':
msg += "Paramiko is required for ssh tunneled connections on Windows."
else:
msg += "use OpenSSH."
raise ImportError(msg)
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
#client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True)
except paramiko.AuthenticationException:
return False
else:
client.close()
return True
示例5: _paramiko_tunnel
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
"""Function for actually starting a paramiko tunnel, to be passed
to multiprocessing.Process(target=this), and not called directly.
"""
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True, password=password)
# except paramiko.AuthenticationException:
# if password is None:
# password = getpass("%s@%s's password: "%(username, server))
# client.connect(server, port, username=username, password=password)
# else:
# raise
except Exception as e:
print('*** Failed to connect to %s:%d: %r' % (server, port, e))
sys.exit(1)
# Don't let SIGINT kill the tunnel subprocess
signal.signal(signal.SIGINT, signal.SIG_IGN)
try:
forward_tunnel(lport, remoteip, rport, client.get_transport())
except KeyboardInterrupt:
print('SIGINT: Port forwarding stopped cleanly')
sys.exit(0)
except Exception as e:
print("Port forwarding stopped uncleanly: %s"%e)
sys.exit(255)
示例6: _paramiko_tunnel
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
"""Function for actually starting a paramiko tunnel, to be passed
to multiprocessing.Process(target=this), and not called directly.
"""
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True, password=password)
# except paramiko.AuthenticationException:
# if password is None:
# password = getpass("%s@%s's password: "%(username, server))
# client.connect(server, port, username=username, password=password)
# else:
# raise
except Exception as e:
print('*** Failed to connect to %s:%d: %r' % (server, port, e))
sys.exit(1)
# print('Now forwarding port %d to %s:%d ...' % (lport, server, rport))
try:
forward_tunnel(lport, remoteip, rport, client.get_transport())
except KeyboardInterrupt:
print('SIGINT: Port forwarding stopped cleanly')
sys.exit(0)
except Exception as e:
print("Port forwarding stopped uncleanly: %s"%e)
sys.exit(255)
示例7: _paramiko_tunnel
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
"""Function for actually starting a paramiko tunnel, to be passed
to multiprocessing.Process(target=this), and not called directly.
"""
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True, password=password)
# except paramiko.AuthenticationException:
# if password is None:
# password = getpass("%s@%s's password: "%(username, server))
# client.connect(server, port, username=username, password=password)
# else:
# raise
except Exception as e:
print ('*** Failed to connect to %s:%d: %r' % (server, port, e))
sys.exit(1)
# Don't let SIGINT kill the tunnel subprocess
signal.signal(signal.SIGINT, signal.SIG_IGN)
try:
forward_tunnel(lport, remoteip, rport, client.get_transport())
except KeyboardInterrupt:
print ('SIGINT: Port forwarding stopped cleanly')
sys.exit(0)
except Exception as e:
print ("Port forwarding stopped uncleanly: %s"%e)
sys.exit(255)
示例8: client
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def client(self):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
cfg = {
"hostname": self.host.name,
"port": int(self.host.port) if self.host.port else 22,
"username": self.host.user,
"timeout": self.timeout,
}
if self.ssh_config:
with open(self.ssh_config) as f:
ssh_config = paramiko.SSHConfig()
ssh_config.parse(f)
self._load_ssh_config(client, cfg, ssh_config)
else:
# fallback reading ~/.ssh/config
default_ssh_config = os.path.join(
os.path.expanduser('~'), '.ssh', 'config')
try:
with open(default_ssh_config) as f:
ssh_config = paramiko.SSHConfig()
ssh_config.parse(f)
except IOError:
pass
else:
self._load_ssh_config(client, cfg, ssh_config)
if self.ssh_identity_file:
cfg["key_filename"] = self.ssh_identity_file
client.connect(**cfg)
return client
示例9: _paramiko_tunnel
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
"""Function for actually starting a paramiko tunnel, to be passed
to multiprocessing.Process(target=this), and not called directly.
"""
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
#client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True, password=password)
# except paramiko.AuthenticationException:
# if password is None:
# password = getpass("%s@%s's password: "%(username, server))
# client.connect(server, port, username=username, password=password)
# else:
# raise
except Exception as e:
print('*** Failed to connect to %s:%d: %r' % (server, port, e))
sys.exit(1)
# Don't let SIGINT kill the tunnel subprocess
signal.signal(signal.SIGINT, signal.SIG_IGN)
try:
forward_tunnel(lport, remoteip, rport, client.get_transport())
except KeyboardInterrupt:
print('SIGINT: Port forwarding stopped cleanly')
sys.exit(0)
except Exception as e:
print("Port forwarding stopped uncleanly: %s"%e)
sys.exit(255)
示例10: __connect
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def __connect(self):
try:
self.__ssh = paramiko.SSHClient()
self.__ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
self.__ssh.connect(self.__host, username=self.__user,
password=self.__password, timeout=self.__timeout)
LOG.info("Connected to %s", self.__host)
except paramiko.AuthenticationException:
LOG.error("Authentication failed when connecting to %s",
self.__host)
raise exceptions.NotAuthorized
except paramiko.SSHException:
LOG.error("Could not connect to %s. Giving up", self.__host)
raise
示例11: scp_upload
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def scp_upload(src_blob='Preproc.tar.gz', dst_blob="~", options={'hostname': 'lecun', 'username': 'shawley'}, progress=simple_callback):
# from https://gist.github.com/acdha/6064215
#--- Make the Paramiko SSH thing use my .ssh/config file (b/c I like ProxyCommand!)
client = SSHClient()
client.load_system_host_keys()
client._policy = WarningPolicy()
client.set_missing_host_key_policy(WarningPolicy()) # hmm. WarningPolicy? Most people use AutoAddPolicy.
ssh_config = SSHConfig()
user_config_file = os.path.expanduser("~/.ssh/config")
if os.path.exists(user_config_file):
with open(user_config_file) as f:
ssh_config.parse(f)
cfg = {'hostname': options['hostname'], 'username': options["username"]}
user_config = ssh_config.lookup(cfg['hostname'])
for k in ('hostname', 'username', 'port'):
if k in user_config:
cfg[k] = user_config[k]
if 'proxycommand' in user_config:
cfg['sock'] = ProxyCommand(user_config['proxycommand'])
client.connect(**cfg)
socket_timeout = None # number of seconds for timeout. None = never timeout. TODO: None means program may hang. But timeouts are annoying!
# SCPCLient takes a paramiko transport and progress callback as its arguments.
scp = SCPClient(client.get_transport(), progress=progress, socket_timeout=socket_timeout)
# NOW we can finally upload! (in a separate process)
#scp.put(src_blob, dst_blob) # now in scp_thread
# we want this to be non-blocking so we stick it in a thread
thread = threading.Thread(target=scp_thread, args=(scp,src_blob, dst_blob) )
thread.start()
#scp.close() # now in scp_thread
示例12: _setup_ssh
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _setup_ssh(self,
hostname,
port,
username = None,
password = None):
self.ssh = paramiko.SSHClient()
# ssh_client.load_system_host_keys()
self.ssh.set_missing_host_key_policy(paramiko.WarningPolicy)
self.ssh.connect(hostname, port=port, username=username, password=password)
assert(self.ssh.get_transport().is_active())
transport = self.ssh.get_transport()
transport.set_keepalive(60)
示例13: _setup_ssh
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def _setup_ssh(self,
hostname,
port,
username = None,
password = None):
ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy)
ssh_client.connect(hostname, port=port, username=username, password=password)
assert(ssh_client.get_transport().is_active())
return ssh_client
示例14: run
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def run():
'''
main
'''
passwords = []
for password in open(PASSWORD).read().split('\n'):
passwords.append(password)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy)
for pwd in passwords:
try:
client.connect(TARGET, port=22,
username="root",
password=pwd,
look_for_keys=False,
timeout=10)
_, stdout, stderr = client.exec_command(COMMAND)
print("exec {}:".format(COMMAND))
print(TARGET, stdout, stderr)
except (paramiko.SSHException, paramiko.ssh_exception.NoValidConnectionsError):
continue
client.close()
示例15: main
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import WarningPolicy [as 别名]
def main():
options, server, remote = parse_options()
password = None
if options.readpass:
password = getpass.getpass('Enter SSH password: ')
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
verbose('Connecting to ssh host %s:%d ...' % (server[0], server[1]))
try:
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
look_for_keys=options.look_for_keys, password=password)
except Exception as e:
print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
sys.exit(1)
verbose('Now forwarding remote port %d to %s:%d ...' % (options.port, remote[0], remote[1]))
try:
reverse_forward_tunnel(options.port, remote[0], remote[1], client.get_transport())
except KeyboardInterrupt:
print('C-c: Port forwarding stopped.')
sys.exit(0)