|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /proc/self/root/lib/python2.7/site-packages/ |
Upload File : |
�
�Tc @ sd d Z d d l Td d l Z d d l Z d d g Z d e f d � � YZ d e f d � � YZ d S( s� This class extends pexpect.spawn to specialize setting up SSH connections.
This adds methods for login, logout, and expecting the shell prompt.
$Id: pxssh.py 487 2007-08-29 22:33:29Z noah $
i����( t *Nt ExceptionPxssht pxsshc B s e Z d Z RS( s! Raised for pxssh exceptions.
( t __name__t
__module__t __doc__( ( ( s) /usr/lib/python2.7/site-packages/pxssh.pyR s c B st e Z d Z d d d d d d d � Z d � Z d � Z d d d d d e d
� Z d � Z d d
� Z
d � Z RS( s� This class extends pexpect.spawn to specialize setting up SSH
connections. This adds methods for login, logout, and expecting the shell
prompt. It does various tricky things to handle many situations in the SSH
login process. For example, if the session is your first login, then pxssh
automatically accepts the remote certificate; or if you have public key
authentication setup then pxssh won't wait for the password prompt.
pxssh uses the shell prompt to synchronize output from the remote host. In
order to make this more robust it sets the shell prompt to something more
unique than just $ or #. This should work on most Borne/Bash or Csh style
shells.
Example that runs a few commands on a remote server and prints the result::
import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
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()
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
Note that if you have ssh-agent running while doing development with pxssh
then this can lead to a lot of confusion. Many X display managers (xdm,
gdm, kdm, etc.) will automatically start a GUI agent. You may see a GUI
dialog box popup asking for a password during development. You should turn
off any key agents during testing. The 'force_password' attribute will turn
off public key authentication. This will only work if the remote SSH server
is configured to allow password logins. Example of using 'force_password'
attribute::
s = pxssh.pxssh()
s.force_password = True
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
i i� c C s� t j | d d | d | d | d | d | d | �d | _ d | _ | j | _ d | _ d
| _ d | _ t | _
t | _ d S( Nt timeoutt maxreadt searchwindowsizet logfilet cwdt envs <pxssh>s \[PEXPECT\][\$\#] s PS1='[PEXPECT]\$ 's set prompt='[PEXPECT]\$ 's5 -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'(
t spawnt __init__t Nonet namet
UNIQUE_PROMPTt PROMPTt
PROMPT_SET_SHt PROMPT_SET_CSHt SSH_OPTSt Falset force_passwordt Truet auto_prompt_reset( t selfR R R R R
R ( ( s) /usr/lib/python2.7/site-packages/pxssh.pyR
I s 4 c C s t | � t | � } } | | k rB | | } } | | } } n t | d � } x� t d | d � D]� } | | g d g | } } x� t d | d � D]t } | | d | | d d } }
| | d } | | d | | d k r� | d } n t | |
| � | | <q� Wqf W| | S( sB This calculates the Levenshtein distance between a and b.
i i ( t lent ranget min( R t at bt nt mt currentt it previoust jt addt deletet change( ( s) /usr/lib/python2.7/site-packages/pxssh.pyt levenshtein_distanceg s
!
c C s | j � | j d d d d � t j d � | j � t j d � | j d d d d � } t j d � | j � t j d � | j d d d d � } t j d � | j � t j d � | j d d d d � } | j | | � } t | � } | d k rt St | � | d k rt St S(
s� This attempts to find the prompt. Basically, press enter and record
the response; press enter again and record the response; if the two
responses are similar then assume we are at the original prompt. t sizei'