
    Zd                         d Z ddlZddlZddlZ ej        d          Z G d dej                  Z G d dej                  Z	d Z
d	gZdS )
a  
Sample script showing how to do local port forwarding over paramiko.

This script connects to the requested SSH server and sets up local port
forwarding (the openssh -L option) from a local port through a tunneled
connection to a destination reachable from the SSH server machine.
    Nsshc                       e Zd ZdZdZdS )ForwardServerTN)__name__
__module____qualname__daemon_threadsallow_reuse_address     /lib/python3.11/site-packages/zmq/ssh/forward.pyr   r   $   s        Nr   r   c                       e Zd Zd ZdS )Handlerc           	      *   	 | j                             d| j        | j        f| j                                                  }nO# t          $ rB}t                              d| j        | j        t          |          fz             Y d }~d S d }~ww xY w|+t                              d| j        | j        fz             d S t                              d| j                                        d|                                d| j        | j        f           	 t          j
        | j        |gg g           \  }}}| j        |v rC| j                            d          }t          |          dk    rn]|                    |           ||v rC|                    d          }t          |          dk    rn| j                            |           |                                 | j                                         t                              d	           d S )
Nzdirect-tcpipz$Incoming request to %s:%d failed: %sz9Incoming request to %s:%d was rejected by the SSH server.zConnected!  Tunnel open z -> Ti   r   zTunnel closed )ssh_transportopen_channel
chain_host
chain_portrequestgetpeername	Exceptionloggerdebugreprselectrecvlensendclose)selfchanerwxdatas          r   handlezHandler.handle*   s   	%22$/2((** DD
  	 	 	LL6?DOT!WW=>   FFFFF	 <LLK?DO45   F ((****  """"$/22		
 	
 	
	(mT\4$8"bAAGAq!|q  |((..t99>>		$qyyyyt99>>!!$'''	( 	

%&&&&&s   ?A 
B7B		BN)r   r   r   r'   r   r   r   r   r   )   s#        *' *' *' *' *'r   r   c                      G fddt                     }t          d| f|                                           d S )Nc                       e Zd Z ZZZdS )!forward_tunnel.<locals>.SubHanderN)r   r   r   r   r   r   )remote_hostremote_port	transports   r   	SubHanderr*   [   s         
 
!r   r.   z	127.0.0.1)r   r   serve_forever)
local_portr+   r,   r-   r.   s    ``` r   forward_tunnelr1   W   sl    " " " " " " " " "G " " "
 ;
+Y77EEGGGGGr   r1   )__doc__loggingr   socketserver	getLoggerr   ThreadingTCPServerr   BaseRequestHandlerr   r1   __all__r   r   r   <module>r9      s   (       		5	!	!    L3   
+' +' +' +' +'l- +' +' +'\	H 	H 	H 
r   