python,,try:#大的尝试b


try:#大的尝试bhSession=paramiko.Transport(client)#ssh连接方式bhSession.add_server_key(host_key)#添加服务器的连接密钥server=Server()#启动服务器class开始try:#尝试bhSession.start_server(server=server)#开启服务exceptparamiko.SSHException,x:#报错信息了print‘[-]SSHnegotiationfailed.‘#直接输出chan=bhSession.accept(20)#监听print‘[+]Authentiacated!‘#权限认证printchan.recv(1024)#获取信息chan.send(‘Welcometobh_ssh‘)#发送信息whileTrue:#循环等待try:#尝试command=raw_input("Entercommand:").strip(‘\n‘)#对输入的信息,然后进行转码ifcommand!=‘exit‘:#如果命令为空chan.send(command)#发送命令过去printchan.recv(1024)+‘\n‘#然后等待接收else:chan.send("exit")#否则发送报错信息print‘exiting‘#打印错误信息bhSession.close()#结束raiseException(‘exit‘)exceptKeyboardInterrupt:#异常报错bhSession.close()#结束了exceptException,e:#大的错误print‘[-]Caughtexception:‘+str(e)#提示错误信息try:#关闭连接bhSession.close()except:#如果关闭不了了,那就关闭了passsys.exit(1)#系统报错结束


本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1790076

python

评论关闭