home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
intrnx.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-02-16
|
15KB
|
365 lines
/*--------------------------------------------------------------------------*/
/* */
/* OS/2 2.1 / WARP REXX Driver for IBM TCP/IP version 2.0 / IAK */
/* */
/* INTERNEX.CMD */
/* 1.0 */
/* Multi-number redialing connection script for SlipPm */
/* written by Tim Charron */
/* tcharron@io.org */
/* */
/* December 3 1994 */
/* */
/* .................................................. */
/* */
/* This script is an extension of the ANNEX.CMD script supplied with */
/* OS/2 WARP. It has redial capability built in. It will attempt redials */
/* until a connection is completed. */
/* */
/* This script should be specified on page 1 in the Login Script field for */
/* connections via SlipPm, or using the -connect option if executing slip */
/* directly. */
/* */
/* As well, the specific phone numbers to dial should be identified in the */
/* script below, if you should have multiple numbers to dial. */
/* */
/* You may want to change the modem initialization string. See the file */
/* MODEM.LST in the TCPIP\ETC directory. */
/* */
/* The script parameters specify the username/password combination to use */
/* to log into the terminal server. */
/* */
/* The following should be used in SlipPM: */
/* Login Script: internex.cmd loginid password */
/* */
/* - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* When the script runs, it is automatically passed the interface name for */
/* the interface it is running on as the first argument, followed by the */
/* user arguments. */
/* */
/* The script sends the dial string to the modem and then logs into the */
/* terminal server using the username/password. It then issues the SLIP */
/* command to start SLIP, and parses the resulting output to determine the */
/* appropriate addresses to use. Lastly, it issues ifconfig and route */
/* commands to configure the OS/2 system appropriately. Note that the */
/* configuration assumes a class C netmask for the SLIP interface. */
/* */
/*--------------------------------------------------------------------------*/
parse arg interface , username password
/*--------------------------------------------------------------*/
/* Enter the addresses of your machine and host here */
/*--------------------------------------------------------------*/
os2_address=199.###.###.###
remote_address=198.133.36.254
netmask=255.255.255.0
/*--------------------------------------------------------------*/
/* Enter the PHONE NUMBERS here, and the total number of phone */
/* numbers in dialcmd.0. waittime is how many seconds to wait */
/* for a connection. */
/*--------------------------------------------------------------*/
dialcmd.0=2
dialcmd.1="ATDT 7W 416-363-4621"
dialcmd.2="ATDT 7W 416-363-4151"
waittime=50
/* ------------------------------------------------------------ */
/* Customize this for for your modem make and model */
/* ------------------------------------------------------------ */
/* PPI modem */
modemreset1="ATI2"
modemreset2="ATE1L0M0N1Q0V1W2X4Y0&C1&D2&K3&Q5&R0&S1S7=60"
/*--------------------------------------------------------------------------*/
/* Initialization and Main Script Code */
/*--------------------------------------------------------------------------*/
/* Set some definitions for easier COM strings */
cr='0d'x
crlf='0d0a'x
say ''
say 'INTERNEX - autodialing Script ',
'(interface' interface')'
/* Prompt for missing information */
if dialcmd.1 = '' then do
call charout , 'Dial Command: '
parse pull dialcmd
end
if username = '' | username = '*' then do
call charout , 'User Name: '
parse pull username
end
else do
say 'User:' username
end
if password = '' | password = '*' then do
call charout , 'Password: '
password = readpass()
end
dialcount=0
redialit:
/* Flush any stuff left over from previous COM activity */
/* Each flush_receive will give a .1 second pause. Some modems may require */
/* a longer break between redials */
call flush_receive 'echo'
call flush_receive 'echo'
/* Reset the modem here */
call lineout , 'Reset modem...'
call send modemreset1 || cr
call waitfor 'OK', 5 ; call flush_receive 'echo'
if RC = 1 then do
call lineout , 'Modem not resetting... Trying again'
call send '+++'
call waitfor 'OK', 3
call send 'ATHZ' || cr
call waitfor 'OK', 3
call send modemreset1 || cr
call waitfor 'OK', 5 ; call flush_receive 'echo'
end
call send modemreset2 || cr
call waitfor 'OK', 5 ; call flush_receive 'echo'
if RC = 1 then do
call lineout , 'Modem not resetting... Trying again'
call send '+++'
call waitfor 'OK', 3
call send 'ATHZ' || cr
call waitfor 'OK', 3
call send modemreset2 || cr
call waitfor 'OK', 5 ; call flush_receive 'echo'
end
/* Dial the remote server */
/* Determine which phone number to dial */
dialcount=dialcount+1
if dialcount > dialcmd.0 then
do
dialcount=1
end
dialwhat=dialcmd.dialcount
call charout , 'Now Dialing...'dialwhat
/* Wait for connection */
call send dialwhat || cr
call waitfor2 'CONNECT','BUSY',waittime
if RC = 1 then do
call lineout , 'No answer... Trying again'
signal redialit
end
call waitfor crlf , 4
/* Handle login. We wait for standard strings, and then flush anything */
/* else to take care of trailing spaces, etc.. */
/* call send cr */
call waitfor 'ogin:' ; call flush_receive 'echo'
call send username || cr
call waitfor 'assword:' ; call flush_receive 'echo'
call send password || cr
/* Flush anything else */
call flush_receive 'echo'
/* Now configure this host for the appropriate address, */
/* and for a default route */
say 'SLIP Connection Established'
say 'Configuring local address =' os2_address ', Remote =' remote_address
'ifconfig sl0' os2_address remote_address 'netmask ' netmask
'route add default' remote_address '1'
/* All done */
exit 0
/*--------------------------------------------------------------------------*/
/* send ( sendstring) */
/*..........................................................................*/
/* */
/* Routine to send a character string off to the modem. */
/* */
/*--------------------------------------------------------------------------*/
send:
parse arg sendstring
call slip_com_output interface , sendstring
return
/*--------------------------------------------------------------------------*/
/* waitfor ( waitstring , [timeout] ) */
/*..........................................................................*/
/* */
/* Waits for the supplied string to show up in the COM input. All input */
/* from the time this function is called until the string shows up in the */
/* input is accumulated in the "waitfor_buffer" variable. */
/* */
/* If timeout is specified, it says how long to wait if data stops showing */
/* up on the COM port (in seconds). */
/* */
/*--------------------------------------------------------------------------*/
waitfor:
parse arg waitstring , timeout
if timeout = '' then
timeout = 5000 /* L O N G delay if not specified */
waitfor_buffer = '' ; done = -1; curpos = 1
ORI_TIME=TIME('E')
if (remain_buffer = 'REMAIN_BUFFER') then do
remain_buffer = ''
end
do while (done = -1)
if (remain_buffer \= '') then do
line = remain_buffer
remain_buffer = ''
end
else do
line = slip_com_input(interface,,10)
end
waitfor_buffer = waitfor_buffer || line
index = pos(waitstring,waitfor_buffer)
if (index > 0) then do
remain_buffer = substr(waitfor_buffer,index+length(waitstring))
waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
done = 0
end
call charout , substr(waitfor_buffer,curpos)
curpos = length(waitfor_buffer)+1
if ((done \= 0) & (TIME('E')>timeout)) then do
call lineout , ' WAITFOR: timed out '
done = 1
end
end
timeout=0
RC=done
return RC
/*--------------------------------------------------------------------------*/
/* waitfor2 ( waitstring , killstring, [timeout] ) */
/* modified copy of waitfor by Tim Charron 12/01/94 */
/*..........................................................................*/
/* */
/* Waits for the supplied string to show up in the COM input. All input */
/* from the time this function is called until the string shows up in the */
/* input is accumulated in the "waitfor_buffer" variable. */
/* */
/* If timeout is specified, it says how long to wait if data stops showing */
/* up on the COM port (in seconds). */
/* */
/* If killstring shows up, exits with error */
/*--------------------------------------------------------------------------*/
waitfor2:
parse arg waitstring , killstring, timeout
if timeout = '' then
timeout = 5000 /* L O N G delay if not specified */
waitfor_buffer = '' ; done = -1; curpos = 1
ORI_TIME=TIME('E')
if (remain_buffer = 'REMAIN_BUFFER') then do
remain_buffer = ''
end
do while (done = -1)
if (remain_buffer \= '') then do
line = remain_buffer
remain_buffer = ''
end
else do
line = slip_com_input(interface,,10)
end
waitfor_buffer = waitfor_buffer || line
index = pos(waitstring,waitfor_buffer)
if (index > 0) then do
remain_buffer = substr(waitfor_buffer,index+length(waitstring))
waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
done = 0
end
index = pos(killstring,waitfor_buffer)
call charout , substr(waitfor_buffer,curpos)
curpos = length(waitfor_buffer)+1
if ((done \= 0) & (TIME('E')>timeout)) then do
call lineout , ' WAITFOR2: timed out '
done = 1
end
if ((done \= 0) & (index > 0)) then do
/* call lineout , ' WAITFOR2: kill string detected' */
done = 1
end
end
timeout=0
RC=done
return RC
/*--------------------------------------------------------------------------*/
/* readpass () */
/*..........................................................................*/
/* */
/* Routine used to read a password from the user without echoing the */
/* password to the screen. */
/* */
/*--------------------------------------------------------------------------*/
readpass:
answer = ''
do until key = cr
key = slip_getch()
if key \= cr then do
answer = answer || key
end
end
say ''
return answer
/*--------------------------------------------------------------------------*/
/* flush_receive () */
/*..........................................................................*/
/* */
/* Routine to flush any pending characters to be read from the COM port. */
/* Reads everything it can until nothing new shows up for 100ms, at which */
/* point it returns. */
/* */
/* The optional echo argument, if 1, says to echo flushed information. */
/* */
/*--------------------------------------------------------------------------*/
flush_receive:
parse arg echo
/* If echoing the flush - take care of waitfor remaining buffer */
if (echo \= '') & (length(remain_buffer) > 0) then do
call charout , remain_buffer
remain_buffer = ''
end
/* Eat anything left in the modem or COM buffers */
/* Stop when nothing new appears for 100ms. */
do until line = ''
line = slip_com_input(interface,,100)
if echo \= '' then
call charout , line
end
return