
    hG                         % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJrJ	r	J
r
  S SKJrJr  S SKJr  S SKJr  S SKJrJrJrJrJr  S SKJrJrJr  S SKJrJr  S S	KJ r J!r!   " S
 S\5      r"Sq#\\$S'   Sq%S q&Sq'S q(Sq)S r*S r+S r,S#S jr-S r.S r/S r0S r1S r2 " S S5      r3 " S S\Rh                  5      r4 " S S\Rj                  5      r6 " S S\Rn                  5      r7 " S S\Rp                  5      r8S  r9S! r:\;S":X  a  \*" 5         gg)$    N)AnyListTuple)connectdefault)ConchOptions)
ConchError)channelcommon
connection
forwardingsession)reactorstdiotask)logusage)ioTypenetworkStringc                      \ rS rSr% SrSr/ SQ/ SQ/ SQ/r/ SQ/ SQ/ S	Q/ S
Q/ SQ/ SQ/r\R                  " S/\R                  " SS9\R                  " SS9S.\R                  " 5       \R                  " SS9\R                  " SSS9/S9r/ r\\\\\\4   4      \S'   / r\\\\\\4   4      \S'   S rS rS rS rSrg)ClientOptions   z(Usage:   conch [options] host [command]
zYconch is a SSHv2 client that allows logging into a remote machine and executing commands.)escapee~)localforwardLNz<listen-port:host:port   Forward local port to remote address)remoteforwardRNz<listen-port:host:port   Forward remote port to local address)nullnzRedirect input from /dev/null.)forkfz(Fork to background after authentication.)ttytz-Tty; allocate a tty even if command is given.)nottyTzDo not allocate a tty.)noshellNz"Do not execute a shell or command.)	subsystemsz-Invoke command (mandatory) as SSH2 subsystem.)r$   r&   zlisten-port:host:port)descr)r   r   commandargumentT)r,   repeat)mutuallyExclusive
optActionsextraActionslocalForwardsremoteForwardsc                     US:X  a  SU S'   gUS   S:X  a-  [        U5      S:X  a  [        [        US   5      S-
  5      U S'   g[        U5      S:X  a  XS'   g[        R                  " S	U S
35        g)z*
Set escape character; ``none'' = disable
noneNr   r   ^      @   zBad escape character 'z'.)lenchrordsysexit)selfescs     b/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/conch/scripts/conch.py
opt_escapeClientOptions.opt_escapeO   sl     &=!DNVs]s3x1} SVr!12DNX] NHH-cU"56    c                     UR                  S5      u  p#n[        U5      n[        U5      nU R                  R                  X#U445        g)z8
Forward local port to remote address (lport:host:port)
:N)splitintr3   append)r@   r#   	localPort
remoteHost
remotePorts        rB   opt_localforwardClientOptions.opt_localforward\   sD     -.GGCL)	z	N	_
!!9:.F"GHrE   c                     UR                  S5      u  p#n[        U5      n[        U5      nU R                  R                  X#U445        g)z8
Forward remote port to local address (rport:host:port)
rG   N)rH   rI   r4   rJ   )r@   r#   rM   connHostconnPorts        rB   opt_remoteforwardClientOptions.opt_remoteforwarde   sD     *+&
h_
x=""J80D#EFrE   c                 4    XS'   SR                  U5      U S'   g )Nhost r-   )join)r@   rV   r-   s      rB   	parseArgsClientOptions.parseArgsn   s    V((7+YrE    N)__name__
__module____qualname____firstlineno__synopsislongdescoptParametersoptFlagsr   Completions	CompleterCompleteUserAtHostcompDatar3   r   r   rI   __annotations__r4   rC   rN   rS   rY   __static_attributes__r[   rE   rB   r   r      s   H	*  		
	
M" 	8AE0>KH   +,!OO2IJ"__3JK

 $$&OO),OO*T:
H 8:M4c5c?23498:NDsE#s(O345:7IG,rE   r   optionsc                     [         R                  SS  n SU ;   a%  U R                  S5      nXUS-    U -   n XS-   US-   2	 U S S   H7  n U R                  U5      nUS S S:X  a  XS-      S   S:w  a	  / XUS-   & M5  M7  M9     [	        5       q [
        R                  U 5        [
        S	   (       a  [
        S
   (       a2  [
        S
   S:X  a  [         R                  nO$[        [
        S
   S5      nO[         R                  n[         R                  n[        R                   " U5        U[         l        O[        R"                  " 5         [%        5         [         R&                  R)                  5       n [*        R,                  " U5      q [2        R2                  " [2        R4                  S 5      n [6        R8                  " 5         [.        (       a*  [*        R:                  " U[*        R<                  [.        5        U(       a%  [2        R2                  " [2        R4                  U5        [
        S   (       a  [
        S   (       d  [
        S   (       d3  [2        R2                  " [2        R>                  [2        R@                  5        [         R                  RC                  5       (       a/  [
        S   (       d!  [        SRE                  [
        S   5      5        [         R                  " [F        5        g ! [         a     GM  f = f! [        R                   aC  n[        SU 35        [
        R                  5         [         R                  " S5         S nAGNS nAff = f! [0         a    S q GNf = f! [0         a    S n GNf = f! [.        (       a*  [*        R:                  " U[*        R<                  [.        5        U(       a%  [2        R2                  " [2        R4                  U5        [
        S   (       a  [
        S   (       d  [
        S   (       d4  [2        R2                  " [2        R>                  [2        R@                  5        f f = f)Nr9   z-lr8      z-or   -zERROR: r   logfileza+c                  8    [         R                  " S[        5      $ Nr   )r   	callLater	reConnect)as    rB   <lambda>run.<locals>.<lambda>   s    w'8'8I'FrE   r-   r$   r&   zConnection to {} closed.rV   )$r>   argvindex
ValueErrorr   rj   parseOptionsr   
UsageErrorprintopt_helpr?   stdoutopenstderrr   startLoggingdiscardLogs	doConnectstdinfilenor$   	tcgetattroldBaseExceptionsignalSIGUSR1r   run	tcsetattrTCSANOWSIGWINCHSIG_DFLisattyformat
exitStatus)argsiargur#   realoutfdoldUSR1s           rB   r   r   |   s   88AB<Dt|JJtA%QQAw	

3A2Aw$4A;q>S#8"$Q $9  oGT"
 u~9y!S(JJ+T2

A**
K				BmmB--NNF

;3MM"ckk3/MM&..'2I75>'':JMM&//6>>:
zz79#5(//@AHHZ[  		
  sm*    
 3MM"ckk3/MM&..'2I75>'':JMM&//6>>: ;Ks[   /K+
K= -M &M* +M= +
K:9K:=M8MMM'&M'*M:9M:=CP>c                      SSK Jn   Sq[        R                  " S[
        5        [        R                  " U R                  5       5        e )Nr   failurer8   g{Gz?)	twisted.pythonr   r   r   rq   _stopReactorr   errFailurer   s    rB   handleErrorr      s2    & JdL)GGGOO	rE   c                  P     [         R                  " 5         g ! [         a     g f = fN)r   stopr   r[   rE   rB   r   r      s"     s    
%%c                     S[         S   ;   a*  [         S   R                  SS5      u  [         S'   [         S'   [         R                  (       d  SS/[         l        [         S   (       d  [        R                  " 5       [         S'   [         S   (       d
  S[         S'   O[        [         S   5      [         S'   [         S   n [         S   n[        R                  n[         S	   (       d"  [        R                  " U [         5      [         S	'   [        R                  " [         S   [         [        5       5      n[        R                  " X[         X#5      R                  [        5        g )
N@rV   r9   userz~/.ssh/id_rsaz~/.ssh/id_dsaport   zhost-key-algorithms)rj   rH   	identitysgetpassgetuserrI   r   verifyHostKeygetHostKeyAlgorithmsSSHUserAuthClientSSHConnectionr   
addErrback_ebExit)rV   r   vhkuaos       rB   r   r      s    
gfo+26?+@+@a+H(,o>6?!//+6?gfo.DD


C())0)E)EdG)T%&

#
#GFOWmo
NCOOD2==gFrE   c                 D    SU  3q [        R                  " S[        5        g )Nzconch: exiting with error 皙?)r   r   rq   r   )r#   s    rB   r   r      s    -aS1Jc<(rE   c            	      4   [        [        R                  S5      (       a  [        [        5        [        R
                  (       am  [        R
                   HY  u  p[        R                  " U [        R                  " [        U[        5      5      n[        R
                  R                  U5        M[     [        R                  (       af  [        R                   H6  u  p1[        R                  " SU SU 35        [        R                  X15        M8     [        R                   " SS["        5        [        S   (       a  [        S   (       a  [        R%                  ['        5       5        [        S   (       ao  [(        R*                  " 5       (       a  [(        R,                  " S	5        [(        R.                  " 5         [1        S
5       H  n [(        R2                  " U5        M     g g ! [4         a*  nS	S KnUR6                  UR8                  :w  a  e  S nAMO  S nAff = f)N
sendIgnorez!asking for remote forwarding for rG   beforeshutdownr(   agentr"   r      )hasattrconn	transport
_KeepAliverj   r3   r   	listenTCPr   SSHListenForwardingFactory SSHListenClientForwardingChannelrJ   r4   r   msgrequestRemoteForwardingaddSystemEventTriggerbeforeShutdownopenChannel
SSHSessionosr"   _exitsetsidrangecloseOSErrorerrnoEBADF)rK   hostportr+   rM   r   r   r   s          rB   	onConnectr      sg    t~~|,,4#*#8#8I!!55($DA %%a( $9 $+$:$: JGG7
|1XJOP((> %; 	%%h
NK9!1&v7799HHQK
		qA 	   77ekk) *s   G##
H-HHc                  h    [        5         [        R                  R                  R                  5         g r   )r   r   r   loseConnectionr[   rE   rB   rr   rr   	  s    NN++-rE   c                      [         R                  n U  H6  u  p[        R                  " SU SU 35        [        R                  U5        M8     g )Nzcancelling rG   )rj   r4   r   r   r   cancelRemoteForwarding)r4   rM   r   s      rB   r   r     sA    ++N .
+j\8*56##J/ !/rE   c                  X    [         S   (       d  [        R                  " S[        5        g g )N	reconnectr   )rj   r   rq   r   r[   rE   rB   stopConnectionr     s    ;#|,  rE   c                   ,    \ rS rSrS rS rS rS rSrg)r   i  c                     Xl         S U l        [        R                  " U R                  5      U l        U R
                  R                  S5        g )Ni,  )r   globalTimeoutr   LoopingCall
sendGloballcstart)r@   r   s     rB   __init___KeepAlive.__init__  s5    	!""4??3crE   c                     U R                   R                  SSSS9nUR                  U R                  5        [        R
                  " SU R                  5      U l        g )Ns"   conch-keep-alive@twistedmatrix.comrE   r9   	wantReplyr   )r   sendGlobalRequestaddBoth	_cbGlobalr   rq   	_ebGlobalr   )r@   ds     rB   r   _KeepAlive.sendGlobal!  sM    II''13! ( 
 	
		$..!$..r4>>BrE   c                 j    U R                   (       a"  U R                   R                  5         S U l         g g r   )r   cancel)r@   ress     rB   r   _KeepAlive._cbGlobal(  s*    %%'!%D rE   c                 ~    U R                   (       a,  S U l         U R                  R                  R                  5         g g r   )r   r   r   r   r@   s    rB   r   _KeepAlive._ebGlobal-  s.    !%DII..0 rE   )r   r   r   N)	r\   r]   r^   r_   r   r   r   r   ri   r[   rE   rB   r   r     s    C&
1rE   r   c                   D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)r   i3  c                 8    U q / U l        0 U l        [        5         g r   )r   r3   r4   r   r   s    rB   serviceStartedSSHConnection.serviceStarted4  s     rE   c                 p    U R                   n/ U l         U H  nUR                  5         M     [        5         g r   )r3   r   r   )r@   lfr+   s      rB   serviceStoppedSSHConnection.serviceStopped;  s1    A rE   c                     [         R                  " SU45      nU R                  SUSS9n[        R                  " SU SU 35        UR                  U R                  X5        UR                  U R                  X5        g )N0.0.0.0s   tcpip-forwardr9   r   zrequesting remote forwarding rG   )	r   packGlobal_tcpip_forwardr   r   r   addCallback_cbRemoteForwardingr   _ebRemoteForwarding)r@   rM   r   datar   s        rB   r   %SSHConnection.requestRemoteForwardingB  sq    22Iz3JK""#3TQ"G/
|1XJGH	d..
E	T--zDrE   c                     [         R                  " SU SU 35        X0R                  U'   [         R                  " [        U R                  5      5        g )Nzaccepted remote forwarding rG   )r   r   r4   repr)r@   resultrM   r   s       rB   r   !SSHConnection._cbRemoteForwardingI  sA    -j\8*EF*2J'T(()*rE   c                 j    [         R                  " SU SU S35        [         R                  " U5        g )Nzremote forwarding rG   z failedr   r   )r@   r#   rM   r   s       rB   r   !SSHConnection._ebRemoteForwardingN  s)    $ZL(7CD
rE   c                    [         R                  " SU45      nU R                  SU5        [        R                  " SU 35         U R
                  U	 [        R                  " [        U R
                  5      5        g ! [         a     N6f = f)Nr   s   cancel-tcpip-forwardzcancelling remote forwarding )r   r   r   r   r   r4   	Exceptionr  )r@   rM   r  s      rB   r   $SSHConnection.cancelRemoteForwardingR  s|    22Iz3JK6=/
|<=	##J/ 	T(()*  		s   A< <
B	B	c                    [         R                  " SU< 35        [        R                  " U5      u  pE[         R                  " U R                  5        [         R                  " U5        US   U R                  ;   a5  U R                  US      n[         R                  " SU 35        [        XaX S9$ [        [        R                  S5      e)NzFTCP r9   zconnect forwarding )remoteWindowremoteMaxPacketr   zdon't know about that port)	r   r   r   unpackOpen_forwarded_tcpipr4   SSHConnectForwardingChannelr	   r   OPEN_CONNECT_FAILED)r@   
windowSize	maxPacketr  remoteHPorigHP	connectHPs          rB   channel_forwarded_tcpip%SSHConnection.channel_forwarded_tcpip\  s    %x !%@@F##$A;$---++HQK8IGG))56.I  ..0L rE   c                 :   [         R                  " SU 35        [         R                  " U R                  5        [        U R                  5      S:X  a!  [         R                  " S5        [	        5         g U R
                  R                  S   R                  X5        g )Nzconnection closing r9   zstopping connectionr   )r   r   channelsr;   r   	__class__	__bases__channelClosed)r@   r
   s     rB   r  SSHConnection.channelClosedl  si    %gY/0t}}"GG)* NN$$Q'55dDrE   )r3   r4   N)r\   r]   r^   r_   r   r   r   r   r   r   r  r  ri   r[   rE   rB   r   r   3  s,    E+
+ ErE   r   c                   `    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrg)r   iw  s   sessionc                   ^  [         R                  " ST R                   S35        [        S   (       a.  T R                  R                  T SSSS9nUR                  S 5        [        S	   (       a  g [        S
   (       a  [        S   (       d  [        S   (       d
  [        5         [        R                  " 5       n[        S   (       a'  [        S   (       d  ST l
        T R                  Ul        OT R                  Ul        U 4S jUl        [        R                   " U5      T l        Sn[        S   (       a9  T R                  R                  T S["        R$                  " [        S
   5      5        g [        S
   (       a  [        S   (       a  [&        R(                  S   n[*        R,                  " U[.        R0                  S5      n[2        R4                  " SU5      n[        R6                  " XWS5      nT R                  R                  T SU5        [8        R8                  " [8        R:                  T R<                  5        T R                  R                  T S["        R$                  " [        S
   5      5        g [        S   (       d  [&        R(                  S   n[*        R,                  " U[.        R0                  S5      n[2        R4                  " SU5      n[        R6                  " XWS5      nT R                  R                  T SU5        [8        R8                  " [8        R:                  T R<                  5        T R                  R                  T SS5        g )Nzsession z openr   s   auth-agent-req@openssh.comrE   r9   r   c                 .    [         R                  " U 5      $ r   r  )xs    rB   rt   (SSHSession.channelOpen.<locals>.<lambda>  s    
rE   r(   r-   r$   r&   r   c                 $   > TR                  5       $ r   )sendEOF)r#  r@   s    rB   rt   r$    s    T\\^rE   r   r*   s	   subsystemTERM123456784H s   pty-reqs   execs   shell)r   r   idrj   r   sendRequestr   _enterRawModer   SSHSessionClient
escapeModehandleInputdataReceivedwriteconnectionLostr   
StandardIOr   NSr   environfcntlioctlr$   
TIOCGWINSZstructunpackpackRequest_pty_reqr   r   _windowResized)	r@   foor   cr   termwinszwinSize
ptyReqDatas	   `        rB   channelOpenSSHSession.channelOpenz  s;   (477)5)*7		%%3SA & A II*+9I75>'':JO$$&8WW%5DO!--AN!ZZAN3%%a(
;II!!$fii	@R6STYu~zz&)B
C --e4$88K
		%%dJ
Cfoot/B/BCII!!$79;M1NO7#zz&)B
C --e4$88K
		%%dJ
Cfoot/B/BCII!!$#6rE   c           
      z   US;   a  SU l         U R                  U5        g U R                   S:X  a  U[        S   :X  a  SU l         g U R                   S:X  GaN  SU l         US:X  a!  [        R                  " S5        [        5         g US:X  a  S n[        R                  " S	U5        g US
:X  a;  [        R                  " S5        U R                  R                  R                  5         g US:X  a  U R                  R                  S5        U R                  R                  R                  5       nUR                  5         U HM  nU R                  R                  [        SR!                  X@R                  R                  U   5      5      5        MO     g U R                  SU-   5        g S	U l         U R                  U5        g )N)   
   r9   r   r8      .zdisconnecting from escape   c                     [        5         [        R                  R                  5         [        R                  R                  5         [
        R                  " [
        R                  " 5       [        R                  5        [        5         g r   )_leaveRawModer>   r}   flushr   r   killgetpidr   SIGTSTPr-  r[   rE   rB   _!SSHSession.handleInput.<locals>._  sB    !OJJ$$&IIOO%GGBIIK8!OrE   r      Rzrekeying connection   #s'   
The following connections are open:
z
  #{} {}
   ~)r/  r2  rj   r   r   r   r   rq   r   r   sendKexInitr   r  keyssortr   r   )r@   charrQ  r  	channelIds        rB   r0  SSHSession.handleInput  sa   >!DOJJt__!dgh.?&?DO__!DOt|34 $ !!!Q'-.		##//1

  !OP99--224!)IJJ$$%*11 )99+=+=i+H "* JJtd{#DOJJtrE   c                 :    U R                   R                  U5        g r   )r   r2  r@   r  s     rB   r1  SSHSession.dataReceived  s    

rE   c                 H   U[         R                  :X  a  [        R                  " S[	        U5       S35        [        [        R                  5      [        :X  a*  [        R                  R                  R                  U5        g [        R                  R                  U5        g g )Nzgot z stderr data)r   EXTENDED_DATA_STDERRr   r   r;   r   r>   r   strbufferr2  )r@   r%   r  s      rB   extReceivedSSHSession.extReceived  si    
///GGd3t9+\23cjj!S(

!!''-

  & 0rE   c                 d    [         R                  " S5        U R                  R                  5         g )Nzgot eof)r   r   r   loseWriteConnectionr   s    rB   eofReceivedSSHSession.eofReceived  s    	

&&(rE   c                 l    [         R                  " SU  35        U R                  R                  U 5        g )Nzremote side closed )r   r   r   	sendCloser   s    rB   closeReceivedSSHSession.closeReceived  s(    %dV,-		D!rE   c                     [         R                  " SU  35        [         R                  " [        U R                  R                  5      5        g )Nzclosed )r   r   r  r   r  r   s    rB   closedSSHSession.closed  s0    '$ !TYY''()rE   c                     [        [        R                  " SU5      S   5      q[        R
                  " S[         35        g )Nz>Lr   zexit status: )rI   r:  r;  r   r   r   r]  s     rB   request_exit_statusSSHSession.request_exit_status  s/    tT2156
-
|,-rE   c                 :    U R                   R                  U 5        g r   )r   r&  r   s    rB   r&  SSHSession.sendEOF  s    		$rE   c                 8    U R                   R                  5         g r   )r   pauseProducingr   s    rB   stopWritingSSHSession.stopWriting  s    

!!#rE   c                 8    U R                   R                  5         g r   )r   resumeProducingr   s    rB   startWritingSSHSession.startWriting  s    

""$rE   c                    [         R                  " S[        R                  S5      n[        R
                  " SU5      nUS   US   US   US   4nU R                  R                  U S[        R                  " S/UQ76 5        g )	Nr   r(  r)  r9   r8   r   s   window-changez!4L)	r7  r8  r$   r9  r:  r;  r   r,  pack)r@   r   rA  rB  newSizes        rB   r=  SSHSession._windowResized  sk    As~~z:--e,!*gaj'!*gaj@		d$4fkk%6R'6RSrE   )r/  r   N)r\   r]   r^   r_   namerD  r0  r1  rc  rg  rk  rn  rq  r&  rw  r{  r=  ri   r[   rE   rB   r   r   w  sF    D'7V+Z')"*
.
 $%TrE   r   c                       \ rS rSrSrg)r   i  r[   Nr\   r]   r^   r_   ri   r[   rE   rB   r   r         rE   r   c                       \ rS rSrSrg)r  i  r[   Nr  r[   rE   rB   r  r    r  rE   r  c                      [         (       d  g [        R                  R                  5       n [        R
                  " U [        R                  [        5        Sq g rp   )
_inRawModer>   r   r   r$   r   r   _savedRawMode)r   s    rB   rL  rL    s5    :				BMM"ckk=1JrE   c                     [         (       a  g [        R                  R                  5       n  [        R
                  " U 5      nUS S  nUS   [        R                  -  US'   US   [        R                  [        R                  -  [        R                  -  [        R                  -  [        R                  -  [        R                  -  [        R                  -  ) -  US'   [        [        S5      (       a  US   [        R                  ) -  US'   US   [        R                   [        R"                  -  [        R$                  -  [        R$                  -  [        R&                  -  [        R(                  -  [        R*                  -  ) -  US'   [        [        S5      (       a  US   [        R,                  ) -  US'   US   [        R.                  ) -  US'   SUS   [        R0                  '   SUS   [        R2                  '   Uq[        R6                  " U [        R8                  U5        Sq g ! [:         a    [<        R>                  " S5         g f = f)Nr   IUCLCr   IEXTENr9      znot a typewriter!) r  r>   r   r   r$   r   IGNPARISTRIPINLCRIGNCRICRNLIXONIXANYIXOFFr   r  ISIGICANONECHOECHOEECHOKECHONLr  OPOSTVMINVTIMEr  r   r   r   r   r   )r   r   news      rB   r-  r-    s   z				B*mmB!f
 Q#**$AQJJiiii ii hh	
 ii ii
 
A 3  Vsyyj(CF QHHjjhh hh ii	
 ii jj
 
A 3!!Vszzk)CF Q399*$AAsxxAsyyb#++s+
O  %#$%s   H/ / II__main__)returnN)<r7  r   r   r   r:  r>   r$   typingr   r   r   twisted.conch.clientr   r   twisted.conch.client.optionsr   twisted.conch.errorr	   twisted.conch.sshr
   r   r   r   r   twisted.internetr   r   r   r   r   r   twisted.python.compatr   r   r   rj   rh   r   r   r   r  r  r   r   r   r   r   r   rr   r   r   r   r   
SSHChannelr   r   r  rL  r-  r\   r[   rE   rB   <module>r     s     	   
 
 # # 1 5 * N N 1 1 % 7R,L R,l  


9x
G,)!H.
0-
1 12AEJ,, AEHET## ETP	z'R'R 		*"H"H 	/d zE rE   