home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / autotelnet < prev    next >
Text File  |  2020-01-01  |  5KB  |  125 lines

  1. #!/usr/local/bin/kermit +
  2.  
  3. ; Illustration of scripted Telnet login using C-Kermit 7.0 or K95 1.1.19.
  4. ;
  5. ; F. da Cruz, Columbia University Kermit Project, August 1999.
  6. ; Revised February 2000 for portability between K95 and C-Kermit.
  7. ;
  8. ; Optional command-line parameters:
  9. ;  1. Hostname or address
  10. ;  2. Username on host
  11. ;  3. Password on host
  12. ;
  13. ; Parameters not supplied are prompted for.
  14. ; Uses Telnet port (23) only since a login dialog is assumed.
  15. ; Write a different script for accessing non-Telnet ports, in which:
  16. ;  . The service port is an additional parameter
  17. ;  . "set host <name> /telnet" is replaced by "set host <name> <port>"
  18. ;  . The dialog section is removed or modifed appropriately.
  19. ; Omit the "/telnet" switch for ports that do not use Telnet protocol.
  20. ;
  21. ; WARNING: This is just an illustration.  It works with most Telnet servers,
  22. ; but is not general enough to work with all.  Prompts might be different,
  23. ; some terminal-related escape sequences might need to be exchanged, etc.
  24. ; See Chapter 19 of "Using C-Kermit" for details.
  25. ;
  26. define badversion {
  27.     echo Sorry - C-Kermit 7.0 or K95 1.1.19 or later required.
  28.     exit 1
  29. }
  30. if not equal "\v(program)" "C-Kermit" badversion
  31. if LLT \v(version) 700196 badversion
  32.  
  33. ; From here down we make free use of C-Kermit 7.0 / K95 1.1.19 features.
  34.  
  35. local kerbang                ; Invoked as Kerbang script?
  36. .kerbang = 0                ; Assume no.
  37. if eq "\%0" "\v(cmdfil)" .kerbang = 1    ; This means we were.
  38.  
  39. define ERRQUIT {            ; Macro to exit appropriately
  40.     if def \%1 echo \%1            ; with an error message.
  41.     if \m(kerbang) exit 1        ; If Kerbang script, exit all the way.
  42.     stop 1                ; Otherwise return to Kermit prompt.
  43. }
  44.  
  45. check network
  46. if fail errquit {Sorry, this version of Kermit does not support TCP/IP.}
  47. set network type tcp/ip
  48. if fail errquit {Sorry, this version of Kermit does not support TCP/IP.}
  49.  
  50. while not def \%1 {            ; If hostname/address not supplied
  51.     ask \%1 { Host: }            ; prompt for one until we get it.
  52.     if > \fsplit(\%1,,,.) 1 {        ; Allow only one "word" here.
  53.         echo Just the address please.    ; E.g. no TCP port number.
  54.         undef \%1
  55.     }
  56. }
  57. if not def \%2 {            ; If username not supplied
  58.     ask \%2 { User [\v(user)]: }    ; Prompt for one, but default
  59.     if not def \%2 assign \%2 \v(user)    ; to local user ID.
  60. }
  61. set telnet environment user \%2        ; Make sure correct userid is sent
  62.  
  63. ; To force the remote host to issue a login (username) prompt, uncomment
  64. ; the following command.  This is necessary if your local and remote user
  65. ; IDs are not the same.
  66. ;
  67. ;;; set login userid
  68.  
  69. ; This script assumes that authenticated logins are not being performed
  70. ; via Kerberos, SRP, or any other supported method.
  71.  
  72. set telopt start-tls refuse        ; Do not use START_TLS option
  73. set telopt authentication refuse    ; Do not use AUTH option
  74. set telopt encrypt refuse refuse    ; Do not use ENCRYPT option
  75.  
  76. ;;; log session session.log             ; Uncomment to log the session
  77.  
  78. echo Connecting to \%1 as user \%2...
  79.  
  80. ; Change the following statement if login on non-Telnet port is desired.
  81.  
  82. set host \%1 23 /telnet            ; Force Telnet protocol negotiations
  83. if fail errquit {Can't open Telnet connection to \%1.}
  84.  
  85. ; Prompt for password if necessary but only after connection is made
  86. ; (there's no point in asking for it if the connection failed).
  87.  
  88. while not defined \%3 {
  89.     askq \%3 { Password for \%2 at \%1: }
  90. }
  91. set input echo off            ; Don't echo scripted interactions.
  92.  
  93. ; Note that some Telnet servers get your user ID automatically in Telnet
  94. ; negotiations and so only prompt for Password:, so look for both at once.
  95. ; Also allow username prompt to be "login:" (UNIX) or "Username:" (VMS).
  96. ; Also allow for the fact that some servers prompt "Password for <username>:",
  97. ; whereas most others prompt just "Password:".
  98. ;
  99. minput 20 login: Username: Password: {Password for \%2:}
  100. if fail errquit {Timed out waiting for initial prompt: \v(inwait) sec.}
  101. if ( = \v(minput) 1 || = \v(minput) 2 ) {
  102.     lineout \%2                        ; User ID required - send it.
  103.     minput 10 Password: {Password for \%2:}
  104.     if fail errquit {Timed out waiting for Password prompt: \v(inwait) sec.}
  105. }
  106. lineout \%3                ; Send password
  107. undef \%3                ; Erase password from memory
  108. if \m(kerbang) {            ; Automatic exit on connection loss.
  109.     set exit on-disconnect on
  110. }
  111.  
  112. ; The CONNECT command sends you online for an interactive session.  Instead
  113. ; of CONNECT, you can substitute additional scripting for automation of any
  114. ; interactions you would do by hand: use INPUT, OUTPUT, IF FAIL (or IF
  115. ; SUCCESS), and other scripting commands for this.  In a common example,
  116. ; you can start a Kermit server on the remote end and then transfer and/or
  117. ; manage remote files from this script.
  118.  
  119. connect
  120.  
  121. ; At this point, escaping back while the connection is open will give you
  122. ; the Kermit command prompt unless you include additional commands below.
  123.  
  124. End ; of Kermit sample Telnet script.
  125.