本文整理汇总了Python中pxssh.pxssh函数的典型用法代码示例。如果您正苦于以下问题:Python pxssh函数的具体用法?Python pxssh怎么用?Python pxssh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pxssh函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, user='sa', host='jj.ax.lt', pswd='', remote=False):
#Instance variables
#self.startupScript = '/Users/jack/.mcserver/start.sh'
self.startupScript = '/home/sa/bukkit/minecraft.sh'
self.bukkitDir = os.path.split(self.startupScript)[0]
self.remote=remote
self.user=user
self.host=host
self.pswd=pswd
if remote:
self.remoteStatusPX = pxssh.pxssh()
self.remoteStatusPX.login(host, user, pswd)
#Check the server status. If it is already running, resume it
if self.status():
print 'Resuming already running server.'
if self.remote:
self.mcServer = pxssh.pxssh()
self.mcServer.login(self.host, self.user, self.pswd)
self.mcServer.sendline('screen -rd mc')
else:
self.mcServer = pexpect.spawn('screen -rd mc')
else:
print 'Server not running. Start with myServer.start()'
开发者ID:doctoboggan,项目名称:blankkit,代码行数:26,代码来源:Server.py
示例2: __init__
def __init__(self, user=None, password=None, host=None, logfile=None, environment=None, verbose=False,
virtualenv=None, working_dir=None):
"""
:param user: the remote user account
:type user: str
:param password: the password for the remote user account
:type password: str
:param host: the remote machine
:type host: str
:param logfile: optional logfile
:type logfile: str
:param environment: Optional key to Project.prefix and Project.postfix dictionaries
:type environment: str
:param verbose: extra logging
:type verbose: bool
:param virtualenv: directory that contains a virtual environment to activate upon connection
:type virtualenv: str
"""
super(RemoteShell, self).__init__(is_remote=True, verbose=verbose)
if not user:
user = Project.user
if not host:
host = Project.address
Project.user = user
Project.password = password
Project.address = host
self.ssh = pxssh(timeout=1200)
try:
if password:
self.ssh.login(host, user, password)
else:
self.ssh.login(host, user)
except ExceptionPxssh:
if not password:
password = Project.password
if not password:
password = getpass('password for {user}@{host}: '.format(user=user, host=host))
self.ssh.close()
self.ssh = pxssh(timeout=1200)
self.ssh.login(host, user, password)
self.accept_defaults = False
self.logfile = logfile
self.prefix = []
self.postfix = []
if environment:
self.prefix.extend(Project.prefix[environment] or [])
self.postfix.extend(Project.postfix[environment] or [])
if working_dir:
self.prefix.insert(0, "cd {dir} ; ".format(dir=working_dir))
if virtualenv:
self.prefix.insert(0, "source {path}/bin/activate ; ".format(path=virtualenv))
开发者ID:pombredanne,项目名称:herringlib,代码行数:51,代码来源:remote_shell.py
示例3: __init__
def __init__(self, username, password, hostname="127.0.0.1"):
self.username = username
self.password = password
self.hostname = hostname
self.process = pxssh.pxssh()
self.process.login(hostname, username, password)
开发者ID:RUBi-ZA,项目名称:JMS,代码行数:7,代码来源:shell.py
示例4: node_reboot
def node_reboot(tokenid, hostname, username, password, ip_address=''):
if ip_address == '':
nicinfo = node_nic_info(tokenid, hostname)
ip_address = nicinfo.get_ip_address(nicinfo.M_PLANE)
if (ip_address == -1):
print '#### node_reboot get_nic Error'
return -1
try:
s2 = pxssh.pxssh()
s2.login(ip_address, username, password)
s2.sendline('sudo reboot')
s2.expect('.*password for .*', timeout=2*600)
s2.sendline(password)
s2.prompt()
s2.logout()
return 0
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
print "use bmc reboot."
ret = bmc_reboot(tokenid, hostname)
return ret
开发者ID:oolorg,项目名称:ool-testshell-backup-initialize,代码行数:26,代码来源:fuel_utls.py
示例5: executeCommand
def executeCommand(command,master = True):
ollin = pxssh.pxssh()
if not ollin.login('ollin.fisica.unam.mx','root'):
print "ssh session failed longin"
print str(ollin)
else:
print "ssh session login successful"
if master == False:
for i in range(1,3):
ollin.sendline('ssh [email protected]'+str(i))
ollin.sendline(command)
ollin.prompt()
print ollin.before
else:
ollin.sendline(command)
for i in range(1,3):
ollin.sendline('ssh [email protected]'+str(i))
ollin.sendline(command)
ollin.prompt()
print ollin.before
ollin.logout()
开发者ID:ismaeIfm,项目名称:ollin_project,代码行数:27,代码来源:Ollin_alberto.py
示例6: verify_control
def verify_control(self, targetnode_ip):
result = True
handle = pxssh.pxssh()
ip = targetnode_ip
login = "root"
passwd = 'c0ntrail123'
prompt = "#"
try:
ret = handle.login (ip,login,passwd,original_prompt=prompt, login_timeout=1000,auto_prompt_reset=False)
except:
pass
cmd = "contrail-status"
output = send_cmd(handle,cmd,prompt,120)
pattern = ["supervisor-control: active",
"contrail-control active",
"contrail-control-nodemgr active",
"contrail-dns active",
"contrail-named active"]
for line in pattern:
if line not in output:
print 'verify %s has Failed' %line
result = result and False
print "result of verify_control %s"%result
assert result
return result
开发者ID:Akilesh1597,项目名称:contrail-server-manager,代码行数:25,代码来源:test_smgr_provision.py
示例7: __init__
def __init__(self,_host,_user,_psw,_port=None) :
self.host = _host
self.user = _user
self.psw = _psw
self.port = _port
self.ssh = pxssh.pxssh()
self.login = False
开发者ID:waterdiviner,项目名称:AppOps,代码行数:7,代码来源:qtsssh.py
示例8: connect
def connect(host, user, password, release):
global Found
global Fails
# debugging shows thread name and hex location
# print current_thread()
# attempt login with pxssh
try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+] Password Found: ' + password
Found = True
# error check
except Exception, e:
# if read_nonblocking si thrown
if 'read_nonblocking' in str(e):
# debugging print 'in fail 1'
Fails += 1
time.sleep(5)
connect(host, user, password, False)
# if synchronize with original prompt is thrown
elif 'synchronize with original prompt' in str(e):
# debugging print 'in fail 2'
time.sleep(1)
connect(host, user, password, False)
开发者ID:bbills85,项目名称:code,代码行数:25,代码来源:autoSSHv3.py
示例9: main
def main():
s = pxssh.pxssh()
hostname = raw_input('host-ip (without last number): ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
cl = address(username,hostname,password)
for i in range(256):
print i,":"
try:
s.login (cl.us,cl.ip,cl.pwd)
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
cl.next_ip
pass
print "Login Success"
s.sendline ('uptime') # run a command
s.prompt() # match the prompt
print s.before # print everything before the prompt.
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.logout()
开发者ID:ma-tri-x,项目名称:pytry,代码行数:26,代码来源:python_ssh_pi.py
示例10: run
def run(self):
self.setName(self.server_name_) # set the name of thread
try:
s = pxssh.pxssh(options={
"StrictHostKeyChecking": "no",
"UserKnownHostsFile": "/dev/null"})
#s = pxssh.pxssh()
#s.SSH_OPTS += " -o StrictHostKeyChecking=no UserKnownHostsFile=/dev/null"
s.login (self.server_name_,self.user_, self.passwd_, original_prompt='[$#>]')
s.sendline ('hostname;uptime')
#s.prompt()
#ret = s.before
print(s.before)
s.logout()
ret = 0
print('ret: 0')
except pxssh.ExceptionPxssh as e:
#except:
ret = 1
print("pxssh failed on login: ")
#print(e)
print('ret: 1')
self.result_= ret
return self.result_
开发者ID:bostoneboy,项目名称:tita,代码行数:26,代码来源:ssh.py
示例11: sendStartupRequest
def sendStartupRequest(self, entry):
#''' ===== still have prombles I need to debug ===== '''
print("Send request to {addr}".format(addr=entry.strAddr()))
script_dir = "/mnt/images/nfs/new_roystonea_script/roystonea_script/"
script_file = self.convnameType2Script(entry.level)
script_ab_file = script_dir + script_file
log_ab_file = script_dir + "log/{host}-{port}-printout.txt".format(host=entry.host, port=entry.port)
ssh_cmd = "nohup python {script_absolute_filepath} {host} {port} console_off > {log_ab} &".format(
script_absolute_filepath=script_ab_file, host=entry.host, port=entry.port, log_ab=log_ab_file
)
print(ssh_cmd)
account = "ot32em"
passwd = ""
remote = pxssh.pxssh()
t = remote.login(entry.host, account, passwd)
print("Login done")
remote.sendline(ssh_cmd)
remote.prompt()
remote.logout()
print("Update the PM Relation to {host}:{port}.".format(host=entry.host, port=entry.port))
entry.dump_pretty()
req = Message.CmdUpdatePMRelationReq(pm_relation=entry)
res = Client.send_message(entry.addr, req)
开发者ID:ot32em,项目名称:Roystonea,代码行数:27,代码来源:PMM.py
示例12: execute_command
def execute_command(username, password, hostname, command, password=1):
try:
s = pxssh.pxssh()
s.login (hostname, username, password)
print "Repl Leader: "
s.sendline ('riak-repl status | grep "leader: \'"')
s.expect(["password for " + username + ":"])
s.sendline (password)
s.prompt()
print s.before
print "Riak Ping: "
s.sendline ('riak ping')
s.prompt()
print s.before
print "Disk Space: "
s.sendline ('du --max-depth=1 -h /var/lib/riak/')
s.prompt()
print s.before
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
开发者ID:drewkerrigan,项目名称:yolo-octo-ninja,代码行数:29,代码来源:ack_node_statuses.py
示例13: ssh
def ssh(self):
"""Handle SSH login to a host"""
#log.debug('We made it into the SSH function')
#log.debug('instantiating the pxssh object')
self.ses = pxssh.pxssh()
#print 'we just created a pxssh object'
"""
log.debug('The credentials to be used are:')
log_msg = 'host:', self.host
log.debug(log_msg)
log_msg = 'Username:', self.username
log.debug(log_msg)
log_msg = 'Password:', self.passwd
log.debug(log_msg)
"""
try:
log_msg = 'Trying to login to host: ' + self.host + ' as user: ' + self.username\
+ ' with password: ' + self.passwd
log.info(log_msg)
#print 'This is after the log message'
print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
self.ses.login(self.host, self.username, self.passwd)
print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
print self.ses.before
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
开发者ID:muttu2244,项目名称:MyPython,代码行数:31,代码来源:Host.py
示例14: set_switch_mirroring
def set_switch_mirroring(switch_IP,mirrored_port,monitoring_port):
time_lasting_start=time.time()
print '\r\nPlease wait a minute,it is connecting to the switch...'
#login to the switch of being set to mirror
myssh = pxssh.pxssh()
myssh.login1(server=switch_IP,username=username,password=pwd)
if ('10.0.3' in switch_IP):
myssh.sendline('configure')
time.sleep(0.1)
print 'Ports mirrored:'
for c in mirrored_port:
if c!= int(monitoring_port):
print 'ge-1/1/'+str(c),
myssh.sendline('set interface ethernet-switching-options analyzer 1 input egress ge-1/1/'+str(c))
time.sleep(0.1)
myssh.sendline('set interface ethernet-switching-options analyzer 1 input ingress ge-1/1/'+str(c))
time.sleep(0.1)
print '\r\nport monitoring:\r\n'+'ge-/1/1/'+monitoring_port
myssh.sendline('set interface ethernet-switching-options analyzer 1 output ge-1/1/'+monitoring_port)
time.sleep(0.1)
#commit , exit configure,exit login
myssh.sendline('commit')
time.sleep(0.2)
myssh.sendline('exit')
time.sleep(0.1)
myssh.sendline('exit')
time.sleep(0.1)
else:
myssh.sendline('enable')
time.sleep(0.1)
myssh.sendline('configure terminal')
time.sleep(0.1)
print 'Ports mirrored:'
for c in mirrored_port:
if c!= int(monitoring_port):
print 'ethernet-'+str(c),
myssh.sendline('monitor session 1 source ethernet '+str(c)+' both')
time.sleep(0.1)
print '\r\nport monitoring:\r\n'+'ethernet-'+monitoring_port
myssh.sendline('monitor session 1 destination ethernet '+monitoring_port)
time.sleep(0.1)
#commit , exit configure,exit login
myssh.sendline('exit')
time.sleep(0.1)
myssh.sendline('write')
time.sleep(0.1)
myssh.sendline('exit')
time.sleep(0.1)
time_lasting_end=time.time()
print '\r\nIt takes '+str(time_lasting_end-time_lasting_start)+' seconds to set the switch to mirror.\r\n'
return 1
开发者ID:xiaqt78,项目名称:openstack-security-monitor,代码行数:60,代码来源:mirror.py
示例15: delete_switch_mirroring
def delete_switch_mirroring(switch_IP):
print 'Deleting mirroring configure ... '
myssh1 = pxssh.pxssh()
myssh1.login1(server=switch_IP,username=username,password=pwd)
if ('10.0.3' in switch_IP):
time.sleep(0.1)
myssh1.sendline('configure')
time.sleep(0.1)
myssh1.sendline('delete interface ethernet-switching-options analyzer 1')
time.sleep(0.1)
# simulate input space to check more
myssh1.sendline(' ')
time.sleep(0.1)
myssh1.sendline('commit')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
else:
myssh1.sendline('enable')
time.sleep(0.1)
myssh1.sendline('configure terminal')
time.sleep(0.1)
myssh1.sendline('no monitor session 1')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
myssh1.sendline('write')
time.sleep(0.1)
myssh1.sendline('exit')
time.sleep(0.1)
return 1
开发者ID:xiaqt78,项目名称:openstack-security-monitor,代码行数:35,代码来源:mirror.py
示例16: connect
def connect(host, user, password, release):
""" Funcao para conectar via ssh no host alvo """
# Variaveis globais
global Found
global Fails
try:
# Cria um objeto da classe pxssh para conexao via ssh
s = pxssh.pxssh()
# Tenta realizar o login no alvo
s.login(host, user, password)
# Retorna a estancia da conexao
print('[+] Password Found: %s' % (password))
# Seta a variavel global Found como True
Found = True
except Exception as e:
# Se retornar read_nonblocking, aguarda 5segundos para tentar novamente
if 'read_nonblocking' in str(e):
Fails += 1
time.sleep(5)
connect(host, user, password, False)
# Se retornar synchronize with original prompt aguarda 1 segundo para tentar novamente
elif 'synchronize with original prompt' in str(e):
time.sleep(1)
connect(host, user, password, False)
finally:
# Se conseguiu conectar apenas libera a conexao
if release:
connection_lock.release()
开发者ID:smateusjr,项目名称:Violent-Python,代码行数:30,代码来源:3-sshBrute.py
示例17: connect
def connect(host, user, password, release):
global Found
global Fails
try:
#Test if password is valid
s = pxssh.pxssh()
s.login(host, user, password)
print '[+] Password Found: ' + password
Found = True
except Exception, e:
#maxed out the number of connections
if 'read_nonblocking' in str(e):
Fails += 1
time.sleep(5)
connect(host, user, password, False)
elif 'synchronize with original prompt' in str(e):
time.sleep(1)
connect(host, user, password, False)
开发者ID:0x7ab00,项目名称:violent-python-exercises,代码行数:26,代码来源:bf_pxssh.py
示例18: setup_ssh_key
def setup_ssh_key(self):
logging.debug('Performing SSH key setup on %s:%d as %s.' %
(self.hostname, self.port, self.user))
try:
host = pxssh.pxssh()
host.login(self.hostname, self.user, self.password,
port=self.port)
public_key = utils.get_public_key()
host.sendline('mkdir -p ~/.ssh')
host.prompt()
host.sendline('chmod 700 ~/.ssh')
host.prompt()
host.sendline("echo '%s' >> ~/.ssh/authorized_keys; " %
public_key)
host.prompt()
host.sendline('chmod 600 ~/.ssh/authorized_keys')
host.prompt()
host.logout()
logging.debug('SSH key setup complete.')
except:
logging.debug('SSH key setup has failed.')
try:
host.logout()
except:
pass
开发者ID:johnnychan86,项目名称:versiontest,代码行数:29,代码来源:ssh_host.py
示例19: __enter__
def __enter__(self):
cmd = [QEMU, '-kernel', self.kernel, '-cpu', 'arm1176', '-m',
'256', '-M', 'versatilepb', '-no-reboot', '-nographic', '-append',
'"root=/dev/sda2 panic=1 vga=normal rootfstype=ext4 ' # no comma
'rw console=ttyAMA0"', '-hda', self.image,
'-net', 'user,hostfwd=tcp::10022-:22', '-net', 'nic']
print 'Starting qemu with:\n%s' % ' '.join(cmd)
env = os.environ.copy()
self.process = pexpect.spawn(' '.join(cmd))
# Put this into a log file, see issue 285
self.logfile = open('.qemu_log', 'w')
self.process.logfile = self.logfile
# Give the vm some time to bootup.
time.sleep(50)
self.ssh = None
# Try connection multiple times, the time it takes to boot varies a lot.
for x in xrange(10):
print 'Connection attempt %s' % x
ssh = pxssh.pxssh()
# See https://github.com/pexpect/pexpect/issues/179
ssh.SSH_OPTS = (" -o'StrictHostKeyChecking=no'"
+ " -o'UserKnownHostsFile /dev/null'")
ssh.force_password = True
try:
ssh.login(HOSTNAME, USERNAME, password=PASSWORD, port=PORT)
self.ssh = ssh
# Validate connection.
self.run_command('uptime')
break
except pxssh.ExceptionPxssh, e:
print 'pxssh failed on login.'
print str(e)
except:
开发者ID:ErikCorryGoogle,项目名称:fletch,代码行数:33,代码来源:raspbian_prepare.py
示例20: __init__
def __init__(self,hostIP, hostUser, hostPass):
self.user=hostUser
self.host=hostIP
self.userpass=hostPass
#self.rootpass=password
self.userClient=pxssh.pxssh()
开发者ID:serdaltopkaya,项目名称:serverPanel,代码行数:7,代码来源:SSHConnection.py
注:本文中的pxssh.pxssh函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论