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

  1. #!/usr/local/bin/kermit +
  2. #
  3. # Modem test script.
  4. # Runs on UNIX, VMS, and Windows 95/98/NT/2000.
  5. # Requires C-Kermit 7.0 or K95 1.1.18 or later.
  6. #
  7. # Dials two (or more) different modem pools repeatedly.
  8. # Logs connection & performance statistics for comparison in modem.log file.
  9. # Connection statistics are supported for USR and Compaq modems.
  10. # Performance stats come from up- and downloading a file of your choice.
  11. #
  12. # The script runs forever, with a chance to exit at the end of each trip
  13. # through the loop ("Press any key within 5 seconds").
  14. #
  15. # In UNIX only, give this script execute permission and make sure the top
  16. # line points at the C-Kermit 7.0 Beta.06 (or later) executable, and then 
  17. # you can run it just like a shell script, in which case it accepts the
  18. # following optional command-line arguments:
  19. #
  20. #  1. hostname
  21. #  2. username on host
  22. #  3. name of local file to up- and download
  23. #
  24. # For example: "modemtest somehost.columbia.edu olaf test.zip"
  25. #
  26. # If these are not supplied the script prompts for them.
  27. # You are prompted for the password in any case.
  28. #
  29. # Other parameters can be passed as environment variables:
  30. #
  31. #  DEVICE - Name of dialout device
  32. #  MODEM  - A C-Kermit/K95 "set modem type" keyword
  33. #  SPEED  - Serial port speed (default 115200)
  34. #
  35. # The default device for UNIX is /dev/cua and for Win95/98/NT it's TAPI.
  36. # The default modem type for UNIX is USROBOTICS.
  37. #
  38. # Author: F. da Cruz, Columbia University, 30 Apr 1999
  39. #
  40. # Modified 19 May 1999
  41. #  . New USRSTATS macro illustrates a cleaner report-parsing method.
  42. #  . New SET BELL OFF command added for silence.
  43.  
  44. define badversion echo C-Kermit 7.0 or K95 1.1.18 Beta.06 required, exit
  45. if LLT \v(version) 70000 badversion
  46.  
  47. local origin model firmware \&n[] \%i \%j \%n 
  48. local debug retrains blers ispeed ospeed
  49. local user pass host file upcps dncps head
  50.  
  51. ; Configuration parameters -- change as needed (*)
  52.  
  53. .origin = 212-555-1234                   ; (*) Phone number you're calling from
  54. dcl \&n[] = 555-7654 555-9876            ; (*) Replace by real phone numbers
  55. dcl \&p[4] = abc xyz                     ; (*) Up to 4 possible prompt roots
  56. .\%n := \fdimension(&n)                  ; Number of numbers
  57.  
  58. .debug = 1                               ; (*) Change to 0 for minimal messages
  59. .logfile = modem.log                     ; (*) Log file name
  60.  
  61. ; Device, modem, and speed -- Environment variables override defaults...
  62.  
  63. if not def device .device := \$(DEVICE)  ; Dialout device / port
  64. if not def modem  .modem  := \$(MODEM)   ; Type of modem on port
  65. if not def speed  .speed  := \$(SPEED)   ; Serial port speed
  66.  
  67. switch \v(system) {                      ; Device and modem defaults...
  68.   :win32                                 ; For Windows 95/98/NT/2000
  69.     if not def device .device = tapi     ; (*) Change if necessary
  70.     if not def modem .modem = tapi       ; (*) Ditto
  71.     if not def speed .speed = 115200     ; (*) Port speed - change if necessary
  72.     break
  73.   :unix                                  ; For UNIX...
  74.     if not def device .device = /dev/cua ; (*) Change to your dialout device
  75.     if not def modem .modem = usrobotics ; (*) Change to match your modem
  76.     if not def speed .speed = 115200     ; (*) Port speed - change if necessary
  77.     break
  78.   :vms                                   ; For VMS...
  79.     if not def device .device = TTA0:    ; (*) Change to your dialout device
  80.     if not def modem .modem = usrobotics ; (*) Change to match your modem
  81.     if not def speed .speed = 57600      ; (*) Port speed - change if necessary
  82.     break
  83.   :default
  84.     ; Add others here...
  85.     exit 1 Sorry - this script does not run on \v(platform).
  86. }
  87.  
  88. .model = UNKNOWN                    ; Modem model
  89. .firmware = UNKNOWN                 ; Modem firmware
  90.  
  91. if def \%1 .host := \%1             ; Accept host, user, and filename
  92. if def \%2 .user := \%2             ; from command line (UNIX only)
  93. if def \%3 .file := \%3             ; or from TAKE command line.
  94.  
  95. ; Macro definitions
  96.  
  97. def usrinfo {                       ; Get info about USR modem
  98.     ; If we weren't cheating we'd do ATI6 and parse the results.
  99.     ; See usrgetstats for a non-cheating example.
  100.     ; Meanwhile change the strings to match your own modem.
  101.     .model = USRobotics Courier V.32bis V.34+ Fax
  102.     .firmware = 6.2.3 / 1.2.4
  103. }
  104.  
  105. def cpqinfo {                       ; Get info about Compaq modem
  106.     ; If we weren't cheating we'd do ATI and parse the results.
  107.     ; See cpqgetstats for a non-cheating example.
  108.     ; Meanwhile change the strings to match your own modem.
  109.     .model = Compaq Presario 56K-DF
  110.     .firmware = 1.3.12
  111. }
  112.  
  113. def getmdminfo {                    ; Get modem info.
  114.     switch \v(modem) {
  115.       :usrobotics
  116.          usrinfo, break
  117.       :tapi
  118.       :compaq
  119.          cpqinfo, break
  120.     }
  121. }
  122.  
  123. ; Get and parse a statistics report from a USR modem.
  124. ; This version parses the report on the fly.
  125.  
  126. def usrstats {                      ; Get USR connection statistics.
  127.     local \%x \%y \%z
  128.     clear input
  129.     output ATI6\13                  ; Send ATI6 and parse output.
  130.     set flag off
  131.     set input echo on
  132.     while not flag {
  133.        minput 10  Blers  Retrains  Speed  OK
  134.        switch \v(minput) {
  135.      :1, clear input, input 2 \10, .blers := \fword(\v(input),1), break
  136.      :2, clear input, input 2 \10, .retrains := \fword(\v(input),5), break
  137.      :3, clear input, input 2 \10, .ospeed := \fword(\v(input),1,,/), break
  138.      :4, set flag on, break
  139.        }
  140.     }
  141. }
  142.  
  143. ; Get and parse a statistics report from a USR modem.
  144. ; This version (which works but is not used) reads the whole report at
  145. ; once and parses it afterwards.  The Compaq report parser (next macro)
  146. ; also uses this method.
  147.  
  148. def xusrstats {                     ; Get USR connection statistics.
  149.     local \%x \%y \%z
  150.     clear input
  151.     output ATI6\13                  ; Send ATI6 and parse output.
  152.     input 20 OK          
  153.     if fail end 1
  154.     .\%x := \findex(Retrains Granted,\v(input))
  155.     if \%x .retrains := \fword(\fsubstr(\v(input),\%x),3)
  156.     .\%x := \findex(Blers,\v(input),\%x+16)
  157.     if \%x .blers := \fword(\fsubstr(\v(input),\%x),2)
  158.     .\%x := \findex(Speed,\v(input),\%x+16)
  159.     if \%x .ospeed := \fword(\fsubstr(\v(input),\%x),2,,/)
  160. }
  161.  
  162. ; Get and parse a statistics report from a Compaq modem.
  163. ; This version reads the whole report at once and parses it afterwards.
  164.  
  165. def cpqstats {                      ; Get Compaq connection statistics.
  166.     local \%x \%y \%z
  167.     clear input
  168.     output ATI11\13                 ; Send ATI11 and parse output.
  169.     pause 2
  170.     out \32                         ; Tickle "press any key to continue"
  171.     input 20 OK          
  172.     if fail end 1
  173.     .\%x := \findex(Final   Transmit Carrier Rate,\v(input))
  174.     if \%x .\%y := \fword(\fsubstr(\v(input),\%x),5)
  175.     .\%x := \findex(Final   Receive  Carrier Rate,\v(input))
  176.     if \%x .\%z := \fword(\fsubstr(\v(input),\%x),5)
  177.     if \%x .ospeed := \%y/\%z    
  178.     .\%x := \findex(Receive  Frame Error Count,\v(input))
  179.     if \%x .blers := \fword(\fsubstr(\v(input),\%x),5)
  180.     .\%x := \findex(Retrain by Local  Modem,\v(input))
  181.     if \%x .retrains := \fword(\fsubstr(\v(input),\%x),5)
  182. }
  183. def getmdmstats {                   ; Get modem connection statistics.
  184.     switch \v(modem) {
  185.       :usrobotics
  186.          usrstats, break
  187.       :tapi
  188.       :compaq
  189.          cpqstats, break
  190.     }
  191. }
  192. def openlog {                       ; Open the log file and write heading
  193.     open append \m(logfile)
  194.     if fail exit 1 Can't open log "\m(logfile)"
  195.     writeln file
  196.     writeln file {Time:            \v(date) \v(time)}
  197.     writeln file {Platform:        \v(platform)}
  198.     writeln file {Modem:           \m(model)}
  199.     writeln file {Firmware:        \m(firmware)}
  200.     writeln file {Interface Speed: \m(speed)}
  201.     writeln file {Calling from:    \m(origin)}
  202.     writeln file {Log File:        \m(logfile)}
  203.     writeln file {Test File:       \m(file)}
  204.     writeln file {Test File Size:  \fsize(\m(file))}
  205.     writeln file
  206.     write file   {Date  Time  Number    Speed  Speed-After    }
  207.     writeln file {Blers Retrains   Upload   Download}
  208.     write file   {----------  --------- -----  -----------    }
  209.     writeln file {----- --------  -------   --------}
  210. }
  211. def flushlog {
  212.     close write
  213.     open append \m(logfile)
  214.     if fail exit 1 Can't reopen log "\m(logfile)"
  215. }
  216. define logrecord { writeln file {\m(head)  \%1} } ; Write a log entry
  217.  
  218. define dologin {                     ; Login from terminal server to host
  219.     output telnet \m(host)\13        ; and start Kermit in server mode there.
  220.     input 30 login:
  221.     if fail end 1
  222.     out \m(user)\13
  223.     input 10 Password:
  224.     if fail end 1    
  225.     out \m(pass)\13
  226.     input 60 {$ }
  227.     output kermit -x\13
  228.     input 20 READY TO SERVE...
  229.     if fail end 1
  230. }
  231. def doio {                           ; Transfer a file back & forth 
  232.     set file collision overwrite     ; and get performance statistics
  233.     while exist \m(file) {
  234.         remote cd /tmp
  235.         if fail break
  236.         remote set file collision overwrite
  237.         if eq \v(system) UNIX set wild kermit ; (bug - fix later)
  238.     send \m(file) delete.me
  239.     if fail break
  240.     .upcps := \v(cps)
  241.     get delete.me
  242.     if success .dncps := \v(cps)
  243.         break
  244.     }
  245.     bye
  246. }
  247.  
  248. ; End of macro definitions
  249.  
  250. while not def host {                 ; Get hostname 
  251.     ask host { Host: }               ; if not given on command line...
  252. }
  253. while not def user {                 ; Ditto for username...
  254.     ask user { User: }
  255. }
  256. while not def pass {                 ; Always prompt for password.
  257.     askq pass { Password: }
  258. }
  259. while not def file {                 ; Get filename if not given 
  260.     ask file { File to transfer: }   ; on command line.
  261.     if exist \m(file) break
  262.     echo \m(file) not found.
  263. }
  264. if not equal "\m(device)" "tapi" {   ; Except in K95...
  265.     set modem type \m(modem)         ; Specify modem type
  266.     if fail {                        ; Check for error
  267.         exit 1 {Error: Modem type "\m(modem)" not known}
  268.     }
  269. }
  270. set carrier off                      ; Don't require carrier
  271. set line \m(device)                  ; Open the device
  272. if fail {                            ; Check for failure
  273.     exit 1 {Error: \m(device) not available}
  274. }
  275. set speed \m(speed)                  ; Set the desired speed
  276.  
  277. getmdminfo                           ; Get modem info
  278. set xfer bell off                    ; Turn off annoying bell
  279.  
  280. if \m(debug) {                       ; Echo parameters for this run...
  281.     echo { Device:      \m(device)}
  282.     echo { Speed:       \m(speed)}
  283.     echo { Modem:       \m(modem)}
  284.     echo { Model:       \m(model)}
  285.     echo { Firmware:    \m(firmware)}
  286.     echo { Host:        \m(host)}
  287.     echo { User:        \m(user)}
  288.     echo { Password:    \frepeat(*,\flen(\m(pass)))}
  289.     echo { File:        \m(file)}
  290.     echo { Size:        \fsize(\m(file))}
  291.     set modem speaker on
  292.     set dial display on
  293.     set input echo on
  294.     set xfer display full
  295. } else {
  296.     set modem speaker off
  297.     set dial display off
  298.     set input echo off
  299.     set quiet on
  300.     set xfer display brief
  301. }
  302.  
  303. ; Line is open...
  304.  
  305. set dial retries 0                   ; No redialing
  306. set dial speed-matching off          ; No speed changing
  307. def on_exit hangup                   ; In case of Ctrl-C
  308. set exit warning off                 ; In case of misconfigured modem
  309. set bell off                         ; Silence please
  310. if \m(debug) show comm
  311.  
  312. openlog                              ; Start logging
  313.  
  314. while true {                         ; Loop till user types something
  315.     for \%i 1 \%n 1 {
  316.         .\%9 := \fcvtdate(\v(date) \v(time))
  317.         .date := \fsubstr(\%9,5,2)/\fsubstr(\%9,7,2)
  318.         .time := \fsubstr(\%9,10,2)\fsubstr(\%9,13,2)
  319.         .head := \m(date) \m(time)  \&n[\%i]
  320.         .upcps = FAILED
  321.         .dncps = FAILED
  322.         clear dial-status
  323.         dial \&n[\%i]
  324.         if fail {
  325.             switch \v(dialstatus) {
  326.               :8, logrecord {FAILED: Timed out}, break
  327.               :9, logrecord {FAILED: User canceled}, exit 0
  328.               :10, logrecord {FAILED: Modem not ready}, break
  329.               :default, logrecord {FAILED: "\v(dialresult)"}, break
  330.             }
  331.             continue
  332.         }
  333.         .ispeed := \fword(\v(dialresult),2)
  334.  
  335.         for \%j 1 10 1 {             ; Get terminal server prompt
  336.             output \13
  337.             minput 10 \&p[1] \&p[2]
  338.             if success break
  339.         }
  340.         if = \%i 10 {
  341.         logrecord {FAILED: No terminal server prompt}
  342.         continue
  343.         }
  344.         input 2 >                    ; Do some i/o...
  345.         if success { 
  346.              dologin
  347.              if success doio            
  348.         }
  349.         output \13                   ; Log out from terminal server
  350.         minput 10 \&p[1] \&p[2]
  351.         if success {
  352.             input 2 >
  353.         if success {
  354.         output exit\13
  355.         input 20 NO CARRIER
  356.         if fail hangup
  357.         pause 1
  358.         }
  359.         }
  360.         .retrains = UNKNOWN
  361.         .blers = UNKNOWN    
  362.         .ospeed = UNKNOWN
  363.         output AT\13                 ; Make sure we're in command mode.
  364.         input 3 OK
  365.     if success {                 ; We are - Get statistics from modem.
  366.             getmdmstats
  367.         .\%7 := \flpad(\m(ispeed),5)\flpad(\m(ospeed),13)
  368.         .\%8 := \flpad(\m(blers),7) \flpad(\m(retrains),8)
  369.         .\%9 := \flpad(\m(upcps),9) \flpad(\m(dncps),10)
  370.         logrec {\%7 \%8 \%9}     ; Write log record
  371.         }
  372.     set ask-timer 5
  373.         getc \%j {Press any key within 5 seconds to quit: }
  374.         if not asktimeout exit
  375.         set ask-timer 0
  376.         echo Continuing...
  377.     }
  378. }
  379. exit
  380.