#!/usr/local/bin/expect -f # # Start up a term connection over an rlogin connect # Great for traversing PPP/SLIP or firewall rlogin connections. # # This uses 'expect' which is available in most Tcl archive # directories via ftp. # # Author: Bob Friesenhahn, bfriesen@iphase.com # #From: bfriesen@simple.sat.tx.us (Bob Friesenhahn) #To: libes@cme.nist.gov #Subject: Re: Solaris 2.3 #Date: Fri, 18 Mar 1994 00:19:34 +0600 #I found another use for expect. A popular program in the Linux world is #a program called "term" that provides for usr-level TCP via a dial-up #serial connect. This only works over serial connections. #For most people this would not be a problem. Unfortunately, I sit #behind a firewall on a computer that uses PPP to get to the corporate #network. The administrators are unwilling to install sofware like #"socks" that allows getting to the outside world. The solution was to #use expect to implement a serial connection over rlogin. This works #like a charm. In fact, I appear to sometimes get a better data transfer #rate since term incorporates built-in compression. set inet_host "bogus.com" set user $env(LOGNAME) set CINTR \003 ;# ^C set CSUSP \032 ;# ^Z set remote_term "/usr/local/bin/term" set local_term "/usr/local/bin/term" spawn rlogin -8 "$inet_host" set rlogin_id $spawn_id # Term tuning parameters set window 12 set bps 114688 set time_out 150 set timeout 50 expect { "Last login:" { sleep 2 } Password: { stty -echo send_user "password (for $user) on $inet_host: " expect_user -re "(.*)\n" send_user "\n" send "$expect_out(1,string)\r" stty echo exp_continue } incorrect { send_user "invalid password or account\n" exit } timeout { send_user "connection to $inet_host timed out\n" exit } eof { send_user "connection to host failed: $expect_out(buffer)" exit } } expect -re "(.*)\n" send -- "$remote_term -r -n off -t $time_out -w $window -s $bps\r" expect -- "\r\n" sleep 1 spawn $local_term -n off -t $time_out -w $window -s $bps set term_id $spawn_id send_user "term connection established, ^C to exit\n" log_user 0 expect_after eof exit while (1) { expect { -i $user_spawn_id $CINTR { send -i $rlogin_id "00000" sleep 1 close -i $rlogin_id send_user "Exiting ...\n" exit } -i $rlogin_id -re .+ { send -i $term_id -- $expect_out(buffer) } -i $term_id -re .+ { send -i $rlogin_id -- $expect_out(buffer) } } } ======================