home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / tcp / Networking / TCP / Dial / AmiTCP_dialup / SLIPUP.REXX < prev   
OS/2 REXX Batch file  |  1993-12-28  |  8KB  |  207 lines

  1. Article 19813 of comp.sys.amiga.datacomm:
  2. Newsgroups: comp.sys.amiga.datacomm
  3. Path: news.Hawaii.Edu!ames!sgiblab!swrinde!cs.utexas.edu!koriel!lll-winken.llnl.gov!taurus.cs.nps.navy.mil!rovero
  4. From: rovero@skye.oc.nps.navy.mil (Josh Rovero)
  5. Subject: Improved SLIP script
  6. Message-ID: <CIBKsM.627@taurus.cs.nps.navy.mil>
  7. Sender: news@taurus.cs.nps.navy.mil
  8. Organization: Naval Postgraduate School,Monterey CA
  9. Date: Mon, 20 Dec 1993 06:02:45 GMT
  10. Lines: 193
  11.  
  12. Now that the Christmas tree is up and all the shopping done, I've 
  13. had a chance to clean up  the ARexx script I use for connecting
  14. to a terminal server that assigns dynamic IP addresses.  
  15.  
  16. Be certain to modify all installation specific strings and numbers
  17. before running the script.
  18.  
  19. It should be pretty easy to modify this so that it checks to see
  20. if AmiTCP is already running, and to use AmiTCP's ARexx port. It'll
  21. have to wait until the kids are back in school, though.
  22.  
  23. /* SLIPUP.REXX                                                               */
  24. /*                                                                           */
  25. /* Version 1.0, 11 December 1993, by P.J. Rovero                             */
  26. /*         1.2, 19 December 1993                                             */
  27. /*                                                                           */
  28. /* An ARexx script that will dial a terminal server, connect, determine the  */
  29. /* dynamically assigned IP address, and start the proper components of       */
  30. /* AmiTCP 2.x.  The script uses rexxserdev.library v2.0 by Joseph M.         */
  31. /* Stivaletta.                                                               */
  32. /*                                                                           */
  33. /* Inspired by Dave Bolen's REXX/2 SLIPUP.CMD for IBM OS/2 TCPIP 1.2.1       */
  34. /*                                                                           */
  35. /* ------------------------------------------------------------------------- */
  36.  
  37. /* Start the required libraries                      */
  38.    say 'Opening libraries......'
  39.    check = addlib('rexxsupport.library', 0, -30, 0)
  40.    if (check == 0) then say 'Rexxsupport library did not open...'
  41.    check = addlib('rexxarplib.library',  0, -30, 0)
  42.    if (check == 0) then say 'Rexxarplib did not open......'
  43.    check = addlib('rexxserdev.library',  0, -30, 0)
  44.    if (check == 0) then say 'Rexxserdev did not open......'
  45.  
  46. /* Define modem strings and other initialization stuff     */
  47.    say 'Initializing.........'
  48.    cr               = '0d'x
  49.    crlf             = '0d0a'x
  50.    response         = 'OK'
  51.    dialcommand      = 'ATDT###-####'  /* Put your number here */
  52.    passwd           = 'XXX'||crlf      /* Put your passwd here */
  53.    tsb_prompt       = 'TSB>'||crlf
  54.    slipstr          = 'Your IP'
  55.    slip_cmd         = 'slip'||crlf
  56.    dest_addr        = '###.###.##.##' /* Put your destination IP here */
  57.    buffer           = allocmem( 512 )
  58.    junk             = c2d( buffer )
  59.  
  60. /* Open the serial device and talk to the modem                         */
  61. /* Mine happens to be a 2400 baud Hayes-compatible on serial unit 2     */
  62.    say 'Setting up serial device.....'
  63.    serhandle = SerOpen('serial.device', 2)
  64.    check     = SerClear(serhandle)
  65.    check     = SerSetParms( serhandle, 2400, 8, N, 1, 0 )
  66.    dialstr   = dialcommand||crlf
  67.    check     = SerWrite( serhandle, dialstr, length( dialstr))
  68.  
  69. /* Wait for a connection and the modem status string */
  70.    say 'Dialing the terminal server..... '
  71.    check    = 0
  72.    totalstr = ''
  73.    do forever
  74.       status   = SerQuery( serhandle )
  75.       parse upper var status valid bytes_read status_bits .
  76.       rcvdstr  = SerRead( serhandle, junk, bytes_read )
  77.       totalstr = totalstr||rcvdstr
  78.       check    = modem_query(totalstr)
  79.       if (check == 100) then leave
  80.       result   = delay(100)
  81.    end
  82.  
  83.    totalstr = ''
  84.  
  85.    say 'Modem has connected to the terminal server....'
  86.    result = startslip()
  87.    exit result
  88. /* ------------------------------------------------------------- */
  89.  
  90.  
  91.  
  92.  
  93. /* ------------------------------------------------------------- */
  94. /* procedure startslip                                           */
  95. /* ------------------------------------------------------------- */
  96. /* Start and configure AmiTCP for SLIP                           */
  97.  
  98. startslip:
  99.  
  100. /* send CRLF to terminal server                                  */
  101.    say 'Sent CRLF to server....'
  102.    check      = SerWrite( serhandle, crlf, length( crlf ))
  103.  
  104. /* Wait for 'Password:' prompt           */
  105.    call wait_str('Password:')
  106.    say 'Received password prompt....'
  107.  
  108. /* Send password, wait for TSB> prompt, issue SLIP command      */
  109.    check = SerWrite( serhandle, passwd, length( passwd ))
  110.    say 'Sent password, now waiting for terminal server prompt....'
  111.    call wait_str(tsb_prompt)
  112.    say 'Terminal server prompt received, now sending slip command....'
  113.    check = SerWrite( serhandle, slip_cmd, length( slip_cmd))
  114.    check = SerRead(  serhandle, junk, length(slip_cmd))
  115.    call wait_str(slipstr)
  116.    say 'SLIP address received from terminal server.......'
  117.  
  118. /* Ok, now we have all the data we need to start slip            */
  119. /* Close down the serial port but leave the line up (ignore DTR) */
  120.    check = SerClose( serhandle )
  121.    parse var rcvdstr . 'Your IP address is' a '.' b '.' c '.' d .
  122.    d = strip(d,'T',',')
  123.    ip_addr = a||'.'||b||'.'||c||'.'||d
  124.    say 'The address for this session is ' ip_addr
  125.    say 'Starting AmiTCP....'
  126.  
  127. /* Start AmiTCP                                                  */
  128.    address command
  129.    'run AmiTCP:AmiTCP'
  130.    'sys:rexxc/WaitForPort AMITCP'
  131.    'wait 2 secs'
  132.  
  133. /* Set myhost and env:sana2/slip0.config up to reflect ip_addr   */
  134. /*   *** Be sure to set this for *your* machine and domain ***   */
  135.    'setenv myhost "' ip_addr ' slb'||d||'.cc.nps.navy.mil amiga"'
  136.    check    = open(temp,'env:sana2/slip0.config','W')
  137.    temp_str = 'serial.device 2 2400 '||ip_addr
  138.    check    = writeln(temp,temp_str)
  139.    check    = close(temp)
  140.  
  141. /* Continue AmiTCP configure and startup                         */
  142. /* Configure loopback device                                     */
  143.    'AmiTCP:bin/ifconfig lo/0 127.1'
  144.  
  145. /* Configure SLIP                                                */
  146.    'AmiTCP:bin/ifconfig devs:networks/rhslip.device/0 '||ip_addr||' '||dest_addr||' netmask 255.255.255.0'
  147.  
  148. /* Add route to this host */
  149.    'AmiTCP:bin/route add slb'||d||'.cc.nps.navy.mil localhost'
  150.  
  151. /* Add default gateway; replace with *your* router    */
  152.    'AmiTCP:bin/route add default ###.###.##.#'
  153.  
  154. /* Start the internet super server */
  155.    'run AmiTCP:bin/inetd'
  156.    'mount TCP: from devs:Inet-Mountlist'
  157.    check = freemem(buffer,512)
  158.    say 'AmiTCP started.....'
  159.    return 0
  160. /* ------------------------------------------------------------- */
  161.  
  162.  
  163. /* ------------------------------------------------------------- */
  164. /* Subroutine wait_str  returns when argument string is received */
  165. /* ------------------------------------------------------------- */
  166. wait_str:
  167.  
  168.    teststr = arg(1)
  169.    check = 0
  170.    do until (check ~= 0)
  171.       status = SerQuery( serhandle )
  172.       parse upper var status valid bytes_read status_bits .
  173.       rcvdstr = SerRead( serhandle, junk, bytes_read )
  174.       check   = pos(teststr,rcvdstr)
  175.       test    = delay(50)
  176.    end
  177. return
  178. /* ------------------------------------------------------------- */
  179.  
  180. /* ------------------------------------------------------------- */
  181. /* Subroutine modem_query   determine modem status               */
  182. /* ------------------------------------------------------------- */
  183. modem_query: procedure
  184.  
  185.    teststr = arg(1)
  186.    connectstr       = 'CONNECT'
  187.    busystr          = 'BUSY'
  188.    nocarrierstr     = 'NO CARRIER'
  189.  
  190.    test = pos(connectstr, teststr)
  191.    if (test ~= 0) then return 100
  192.  
  193.    test = pos(busystr, teststr)
  194.    if (test ~= 0) then exit(10)
  195.  
  196.    test = pos(nocarrierstr, teststr)
  197.    if (test ~= 0) then exit(10)
  198.    return 0
  199. /* ------------------------------------------------------------- */
  200. -- 
  201. Josh Rovero   (rovero@oc.nps.navy.mil) | Packet:  KK1D @ K6LY 
  202. Department of Oceanography, Code OC/Rv |       
  203. Naval Postgraduate School              |              
  204. Monterey, CA  93943   (408) 656-2084   |
  205.  
  206.  
  207.