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

  1. #!/usr/local/bin/kermit +
  2. #
  3. # m o d e m t e s t 2
  4. #
  5. # Modem test and statistics -- Works on Windows, UNIX, and VMS.
  6. #
  7. # Requires C-Kermit 7.1
  8. # F. da Cruz, Columbia University, Feb 2001
  9. #
  10. # Sometimes it's easier to hardwire the parameters...
  11. #
  12. .device = com1
  13. .modem = usr
  14. .speed = 115200             ; For USR v.34 use 57600 and for V.90 use 115200
  15. .origin = 212-316-3982
  16. .\%1 = watsun
  17. .\%2 = fdc
  18. .\%3 = test.zip
  19.  
  20. ; Note: phone numbers are fake
  21.  
  22. dcl \&n[] = 5551234 5551235 5551236 5551237 5551238 5551239 5551240 -
  23.             5551241 5551242 5551243 5551244 5551245 5551246 5551247
  24.  
  25. ; Array of terminal server names
  26. dcl \&p[] = ccts1 ccts2 ccts3 ccts4 ccts5 ccts6
  27.  
  28. .\%n := \fdimension(&n)             ; Number of numbers
  29.  
  30. ; Array of terminal server prompts (= name with ">" appended)
  31. dcl \&q[\fdim(&p)]                  
  32. for \%i 1 \fdim(&p) 1 {
  33.   .\&q[\%i] := \&p[\%i]>
  34. }
  35.  
  36. ; This script takes great care to recover from errors so it can run
  37. ; unattended for long periods of time and to record whatever data it got
  38. ; on each run even if the session terminated prematurely.
  39. ;
  40. ; As written, this script assumes a Cisco terminal server that has a
  41. ; "terminal autohangup" command.  SET CARRIER-WATCH is OFF at first, so we
  42. ; can query and then dial the modem.  After successful dialing, we set it
  43. ; ON so we can catch disconnections promptly.  We also send "terminal
  44. ; autohangup" to the Cisco so when the host session terminates (as it
  45. ; should when we send it a BYE command), the terminal server hangs up the
  46. ; modem.  All i/o's are tested for success or failure.  Once the data
  47. ; transfer phase is complete, we SET CARRIER-WATCH OFF again so we can
  48. ; query the modem for stats.
  49. ;
  50. ; Modem queries are supported for US Robotics and Compaq modems, and
  51. ; tested with USR V.34 and "V.Everything" 56K, and Compaq Presario 56K-DF.
  52. ;
  53. define badversion echo C-Kermit 7.1 or K95 1.1.21 or later required, exit
  54. if LLT \v(version) 701199 badversion
  55. if not def \v(buildid) badversion
  56. if LLT \v(buildid) 20001116 badversion
  57.  
  58. ; local model firmware \%i \%j
  59. ; local debug retrains blers ispeed ospeed
  60. ; local user pass host file upcps dncps head tsport seq
  61.  
  62. ; Configuration parameters -- change as needed (*)
  63.  
  64. ;; LOG SESSION session.log append        ; (*) uncomment for extra debugging
  65.  
  66. SET DIAL TIMEOUT 30
  67. SET SEND TIMEOUT 6 FIXED
  68. SET INPUT BUFFER-LENGTH 10240
  69.  
  70. .debug = 1                               ; (*) Change to 0 for minimal messages
  71. .logfile = modem.log                     ; (*) Log file name
  72.  
  73. switch \v(system) {                      ; Device and modem defaults...
  74.   :win32                                 ; For Windows 95/98/NT/2000
  75.     if not def device .device = tapi     ; (*) Change if necessary
  76.     if not def modem .modem = tapi       ; (*) Ditto
  77.     if not def speed .speed = 115200     ; (*) Port speed - change if necessary
  78.     break
  79.   :unix                                  ; For UNIX...
  80.     if not def device .device = /dev/cua ; (*) Change to your dialout device
  81.     if not def modem .modem = usrobotics ; (*) Change to match your modem
  82.     if not def speed .speed = 115200     ; (*) Port speed - change if necessary
  83.     break
  84.   :vms                                   ; For VMS...
  85.     if not def device .device = TTA0:    ; (*) Change to your dialout device
  86.     if not def modem .modem = usrobotics ; (*) Change to match your modem
  87.     if not def speed .speed = 57600      ; (*) Port speed - change if necessary
  88.     break
  89.   :default
  90.     ; Add others here...
  91.     exit 1 Sorry - this script does not run on \v(platform).
  92. }
  93.  
  94. if not def origin .origin = UNKNOWN
  95. .model = UNKNOWN                    ; Modem model
  96. .firmware = UNKNOWN                 ; Modem firmware
  97.  
  98. if def \%1 .host := \%1             ; Accept host, user, and filename
  99. if def \%2 .user := \%2             ; from command line (UNIX only)
  100. if def \%3 .file := \%3             ; or from TAKE command line.
  101.  
  102. ; Macro definitions
  103.  
  104. def usrinfo {                       ; Get info about USR modem
  105.     ; If we weren't cheating we'd do ATI6 and parse the results.
  106.     ; See usrgetstats for a non-cheating example.
  107.     ; Meanwhile change the strings to match your own modem.
  108.     if eq "\v(speed)" "115200" {
  109.         .model = USRobotics Courier V.Everything V.90
  110.         .firmware = 7.3.14 / 3.0.13
  111.     } else {
  112.         .model = USRobotics Courier V.32bis V.34+ Fax
  113.         .firmware = 6.2.3 / 1.2.4
  114.     }
  115. }
  116.  
  117. def cpqinfo {                       ; Get info about Compaq modem
  118.     ; If we weren't cheating we'd do ATI and parse the results.
  119.     ; See cpqgetstats for a non-cheating example.
  120.     ; Meanwhile change the strings to match your own modem.
  121.     .model = Compaq Presario 56K-DF
  122.     .firmware = 1.3.12
  123. }
  124.  
  125. def getmdminfo {                    ; Get modem info.
  126.     switch \v(modem) {
  127.       :usrobotics
  128.          usrinfo, break
  129.       :tapi
  130.       :compaq
  131.          cpqinfo, break
  132.     }
  133. }
  134.  
  135. ; Get and parse a statistics report from a USR modem.
  136. ; This version parses the report on the fly.
  137.  
  138. def usrstats {                      ; Get USR connection statistics.
  139.     local \%x \%y \%z
  140.     clear input
  141.     output ATI6\13                  ; Send ATI6 and parse output.
  142.     set flag off
  143.     set input echo on
  144.     while not flag {
  145.        minput 10  Blers  Retrains  Speed  OK
  146.        switch \v(minput) {
  147.      :1, clear input, input 2 \10, .blers := \fword(\v(input),1), break
  148.      :2, clear input, input 2 \10, .retrains := \fword(\v(input),5), break
  149.      :3, clear input, input 2 \10, .ospeed := \fword(\v(input),1,,/), break
  150.      :4, set flag on, break
  151.        }
  152.     }
  153. }
  154.  
  155. ; Get and parse a statistics report from a USR modem.
  156. ; This version (which works but is not used) reads the whole report at
  157. ; once and parses it afterwards.  The Compaq report parser (next macro)
  158. ; also uses this method.
  159.  
  160. def xusrstats {                     ; Get USR connection statistics.
  161.     local \%x \%y \%z
  162.     clear input
  163.     output ATI6\13                  ; Send ATI6 and parse output.
  164.     input 20 OK          
  165.     if fail end 1
  166.     .\%x := \findex(Retrains Granted,\v(input))
  167.     if \%x .retrains := \fword(\fsubstr(\v(input),\%x),3)
  168.     .\%x := \findex(Blers,\v(input),\%x+16)
  169.     if \%x .blers := \fword(\fsubstr(\v(input),\%x),2)
  170.     .\%x := \findex(Speed,\v(input),\%x+16)
  171.     if \%x .ospeed := \fword(\fsubstr(\v(input),\%x),2,,/)
  172. }
  173.  
  174. ; Get and parse a statistics report from a Compaq modem.
  175. ; This version reads the whole report at once and parses it afterwards.
  176.  
  177. def cpqstats {                      ; Get Compaq connection statistics.
  178.     local \%x \%y \%z
  179.     clear input
  180.     output ATI11\13                 ; Send ATI11 and parse output.
  181.     if fail end 1
  182.     input 6 ESC to quit.
  183.     if fail end 1
  184.     output {\32}                    ; Tickle "press any key to continue"
  185.     minput 20 OK {NO CARRIER}
  186.     if fail end 1
  187.     .\%x := \findex(Final   Transmit Carrier Rate,\v(input))
  188.     if \%x .\%y := \fword(\fsubstr(\v(input),\%x),5)
  189.     .\%x := \findex(Final   Receive  Carrier Rate,\v(input))
  190.     if \%x .\%z := \fword(\fsubstr(\v(input),\%x),5)
  191.     if \%x .ospeed := \%y/\%z    
  192.     .\%x := \findex(Receive  Frame Error Count,\v(input))
  193.     if \%x .blers := \fword(\fsubstr(\v(input),\%x),5)
  194.     .\%x := \findex(Retrain by Local  Modem,\v(input))
  195.     if \%x .retrains := \fword(\fsubstr(\v(input),\%x),5)
  196. }
  197. def getmdmstats {                   ; Get modem connection statistics.
  198.     switch \v(modem) {
  199.       :usrobotics
  200.          usrstats, break
  201.       :tapi
  202.       :compaq
  203.          cpqstats, break
  204.     }
  205. }
  206. def openlog {                       ; Open the log file and write heading
  207.     fopen /append \%c \m(logfile)
  208.     if fail exit 1 Can't open log "\m(logfile)"
  209.     fwrite \%c
  210.     fwrite \%c {Time:            \v(date) \v(time)}
  211.     fwrite \%c {Platform:        \v(platform)}
  212.     fwrite \%c {Software:        \v(xprogram) \v(xversion)}
  213.     fwrite \%c {Modem:           \m(model)}
  214.     fwrite \%c {Firmware:        \m(firmware)}
  215.     fwrite \%c {Interface Speed: \m(speed)}
  216.     fwrite \%c {Calling from:    \m(origin)}
  217.     fwrite \%c {Log File:        \m(logfile)}
  218.     fwrite \%c {Test File:       \m(file)}
  219.     fwrite \%c {Test File Size:  \fsize(\m(file))}
  220.     fwrite \%c
  221.     fwrite /string \%c {Date  Time  Number    Line       Speed  Speed-After  }
  222.     fwrite \%c {Blers Retr Upload  Dnload}
  223.     fwrite /string \%c {----------  -------   --------   -----  -----------  }
  224.     fwrite \%c {----- ---- ------  ------}
  225.     fclose \%c
  226. }
  227.  
  228. define logrecord {                   ; Write a log entry
  229.     if \f_status(\%c) fclose \%c
  230.     fopen /append \%c \m(logfile)
  231.     if fail exit 1 LOG OPEN FAILURE: "\m(logfile)"
  232.     fwrite \%c {\m(head)  \%1}
  233.     if fail exit 1 LOG WRITE FAILURE: "\m(logfile)"
  234.     fclose \%c
  235.     if \m(debug) { echo, echo {\m(head)  \%1} }
  236. }
  237.  
  238. define dologin {                     ; Login from terminal server to host
  239.     output telnet \m(host)\13        ; and start Kermit in server mode there.
  240.     input 40 login:
  241.     if fail end 1
  242.     out \m(user)\13
  243.     input 20 Password:
  244.     if fail end 1    
  245.     out \m(pass)\13
  246.     input 90 {$ }
  247.     output kermit -x\13
  248.     input 60 READY TO SERVE...
  249.     if fail end 1
  250. }
  251.  
  252. def xmsg {                           ; Send message to file transfer display
  253.   if not def \v(buildid) end
  254.   if llt \v(buildid) 20001116 end
  255.   set xfer message \m(seq): \v(dialnumber) (\m(tsport)) \v(time)
  256. }
  257.  
  258. def doio {                           ; Transfer a file back & forth 
  259.     local rc                         ; and get performance statistics
  260.     .rc = 1
  261.     while exist \m(file) {
  262.         remote cd /tmp
  263.         if fail break
  264.         remote set file collision overwrite
  265.         do xmsg
  266.     send \m(file) delete.me
  267.     if fail break
  268.     .upcps := \v(cps)
  269.         do xmsg
  270.     get delete.me
  271.         if fail break
  272.     .dncps := \v(cps)
  273.         .rc = 0
  274.         break
  275.     }
  276.     if not open connection end 1
  277.     bye
  278.     end \m(rc)
  279. }
  280.  
  281. ; End of macro definitions
  282.  
  283. while not def host {                 ; Get hostname 
  284.     ask host { Host: }               ; if not given on command line...
  285. }
  286. while not def user {                 ; Ditto for username...
  287.     ask user { User: }
  288. }
  289. while not def pass {                 ; Always prompt for password.
  290.     askq pass { Password: }
  291. }
  292. while not def file {                 ; Get filename if not given 
  293.     ask file { File to transfer: }   ; on command line.
  294.     if exist \m(file) break
  295.     echo \m(file) not found.
  296. }
  297. if not equal "\m(device)" "tapi" {   ; Except in K95...
  298.     set modem type \m(modem)         ; Specify modem type
  299.     if fail {                        ; Check for error
  300.         exit 1 {Error: Modem type "\m(modem)" not known}
  301.     }
  302. }
  303. set carrier off                      ; Don't require carrier yet
  304. set line \m(device)                  ; Open the device
  305. if fail {                            ; Check for failure
  306.     exit 1 {Error: \m(device) not available}
  307. }
  308. set speed \m(speed)                  ; Set the desired speed
  309.  
  310. getmdminfo                           ; Get modem info
  311. set xfer bell off                    ; Turn off annoying bell
  312.  
  313. if \m(debug) {                       ; Echo parameters for this run...
  314.     echo { Device:      \m(device)}
  315.     echo { Speed:       \m(speed)}
  316.     echo { Modem:       \m(modem)}
  317.     echo { Model:       \m(model)}
  318.     echo { Firmware:    \m(firmware)}
  319.     echo { Host:        \m(host)}
  320.     echo { User:        \m(user)}
  321.     echo { Password:    \frepeat(*,\flen(\m(pass)))}
  322.     echo { File:        \m(file)}
  323.     echo { Size:        \fsize(\m(file))}
  324.     set modem speaker on
  325.     set dial display on
  326.     set input echo on
  327.     set xfer display full
  328. } else {
  329.     set modem speaker off
  330.     set dial display off
  331.     set input echo off
  332.     set quiet on
  333.     set xfer display brief
  334. }
  335.  
  336. ; Device is open...
  337.  
  338. set dial retries 0                   ; No redialing
  339. set dial speed-matching off          ; No speed changing
  340. def on_exit hangup                   ; In case of Ctrl-C
  341. set exit warning off                 ; In case of misconfigured modem
  342. set file collision overwrite         ; Don't pile up lots of backup files
  343. set bell off                         ; Silence please
  344. if \m(debug) show comm
  345.  
  346. openlog                              ; Start logging
  347. .seq = 0                             ; Call number
  348.  
  349. while true {                         ; Loop till user types something
  350.     for \%i 1 \%n 1 {                ; Call each phone number
  351.         incr seq                     ; Count this call
  352.         .status = ERRORS             ; Assume there will be errors (for msg)
  353.         set carrier off              ; For dialing
  354.         .\%9 := \fcvtdate(\v(date) \v(time))
  355.         .date := \fsubstr(\%9,5,2)/\fsubstr(\%9,7,2)
  356.         .time := \fsubstr(\%9,10,2)\fsubstr(\%9,13,2)
  357.         .head := \m(date) \m(time)  \&n[\%i]
  358.         clear dial-status
  359.         dial \&n[\%i]
  360.         if fail {
  361.             switch \v(dialstatus) {
  362.               :8, logrecord {FAILED: Timed out}, break
  363.               :9, logrecord {FAILED: User canceled}, stop
  364.               :10, logrecord {FAILED: Modem not ready}, break
  365.               :default, logrecord {FAILED: "\v(dialresult)"}, break
  366.             }
  367.             continue
  368.         }
  369.     set carrier on               ; For logging in and file transfer
  370.         .ispeed := \fword(\v(dialresult),2) ; Speed from CONNECT message
  371.  
  372.         clear input
  373.     .\%x := 0    
  374.         for \%j 1 10 1 {             ; Get terminal server herald
  375.             output \13
  376.             xecho {#}
  377.             minput 10 \fjoin(&q,,2)
  378.             if success break
  379.         }
  380.         if > \%j 10 {
  381.             logrecord {FAILED: No terminal server prompt}
  382.         continue
  383.         }
  384.     .tmp := \v(input)
  385.         .\%x = \v(minput)
  386.     .\%y = \findex({\&p[\%x] line },\m(tmp))
  387.         .tsport = UNK
  388.     if > \%y 0 {
  389.       .tsport := \flpad(\fword(\s(tmp[\%y]),3),3,0)
  390.     }
  391.     .server := \&p[\%x]
  392.         .tsport := \m(server):\m(tsport)
  393.         .head := \m(head)\flpad(\m(tsport),12)
  394.         .upcps = FAILED
  395.         .dncps = FAILED
  396.         lineout term autohangup
  397.         minput 6 \fjoin(&q,,2)
  398.         if success { 
  399.             dologin
  400.             if success doio            
  401.             if success .status = OK
  402.         }
  403.         pause 1
  404.     set carrier off              ; For getting modem statistics
  405.         hangup                       ; Hang up modem but don't close
  406.         pause 1
  407.         .retrains = UNK
  408.         .blers = UNK
  409.         .ospeed = UNKNOWN
  410.         output AT\13                 ; Make sure we're in command mode.
  411.         input 3 OK
  412.     if success getmdmstats       ; We are - Get statistics from modem.
  413.     .\%7 := \flpad(\m(ispeed),5)\flpad(\m(ospeed),13)
  414.     .\%8 := \flpad(\m(blers),6) \flpad(\m(retrains),4)
  415.     .\%9 := \flpad(\m(upcps),6) \flpad(\m(dncps),7)
  416.     logrec {\%7 \%8 \%9}         ; Write log record
  417.     set ask-timer 5
  418.         echo
  419.         echo     {----------------------------------------}
  420.         echo PASS \m(seq) DONE (\m(status))...
  421.         clear keyboard-buffer
  422.         getc \%j {PRESS ANY KEY WITHIN 5 SECONDS TO QUIT: }
  423.         echo     {----------------------------------------}
  424.         if not asktimeout stop
  425.         set ask-timer 0
  426.         echo
  427.         echo Continuing...
  428.     }
  429. }
  430. exit
  431.