Re: how to force an ssh client timeout

From: Brian Hatch (bri_at_ifokr.org)
Date: 09/11/04

  • Next message: Filip Fafara: "SSH tunelling"
    Date: Fri, 10 Sep 2004 16:49:57 -0700
    To: k l <yoda_2732002@yahoo.com>
    
    
    

    > I need to do this on the ssh client side e.g. if I
    > can not log into a given machine in 10 seconds
    > I want to terminate/close the connection and move
    > on to the next machine. Please note that you may
    > get/establish a TCP connection to the remote server but it
    > may, for some reason, just stay/hang there and
    > you may not be able to log in

    Set up in your ssh connection a local port forward. Test
    in 10 seconds if this forward is alive. If not, kill the connection.

    Here's some perl-style pseudo code:

            sub sshto {
                    $host=@_;

                    if ( fork ) {
                            wait
                    }
                    $sshpid = fork();
                    if ( $sshpid ) {
                            sleep 10;
                            use IO::Socket;
                            if ( IO::Socket::INET->new(
                                   Proto => "tcp",
                                   PeerAddr => "localhost",
                                   PeerPort => $LOCALPORT
                             ) {
                                     exit;
                             } else {
                                     kill 9, $sshpid
                             }
                     } else {
                             exec "ssh -L $LOCALPORT:localhost:22 $SSH_ARGS $host"
                    }
            }

    Since the forward won't exist until ssh has logged in, you should
    be able to catch if it's dead or not.

    -- 
    Brian Hatch                  "When I met him, he was
       Systems and                sullied and tainted.  But
       Security Engineer          now he has been purified
    http://www.ifokr.org/bri/     in the fires of passion."
                                  -- Bree
    Every message PGP signed
    
    



  • Next message: Filip Fafara: "SSH tunelling"