home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
pingal12.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-05-13
|
3KB
|
114 lines
/* PINGAL.CMD: A host alarm for TCP/IP 1.2.1 for OS/2.
This Rexx program will ring an alarm whenever the condition of the
specified host has changed (either connection established or lost).
This way, you can monitor the connection, or run it when the connection is
lost, to be notified when the connection is re-established.
By turgut Kalfaoglu <turgut@frors12.bitnet>
Usage:
PINGAL hostname1 hostname2 hostnameN
*/
parse arg hosts
if hosts = '' then hosts = 'FRORS12.circe.fr'
/* polling delay.. the program gradually gets 'lazier' to poll
to reduce load - up to maxwait seconds:
*/
minwait = 1
maxwait = 15
/* Ping count -- how many times to ping each host, at each interval
(usually 1-10)
*/
pingcount = 10
version = 1.1
curwait = minwait
Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
Call SysLoadFuncs
oldstatus. = -1992
beep = 0
currstatus. = 2
samesince. = time('S')
packet. = 0
upcount. = 0
checkcount. = 0
monstart = time()
'@ECHO OFF'
'@RXQUEUE /CLEAR'
title = Left('Host',20) Left('Status',15) Left('Since',10)'Packet Loss' ' Uptime'
title2 = Left('----',20) left('------',15) left('-----',10)'-----------' ' ------'
Call SysCLS
z = SysCurPos(2,0)
Say title
Say title2
do forever
z = SysCurPos(0,0)
Say 'IP Monitor V'version ' started' monstart 'now' time()' '
do i=1 to words(hosts)
host = subword(hosts,i,1)
blurb = Left(host,20) Left(currstatus(),15) ,
left(samesince(),10) right(packet.host,5)'%' right(upcount(),10)'%'
If beep > 0 Then do
blurb = blurb||'07'x
beep = beep - 1
End
z = SysCurPos(i+3,0)
Say blurb
'@PING' host '8' pingcount '| RXQUEUE'
currstatus.host = 2 /* unknown */
checkcount.host = checkcount.host + 1
do while queued()>0
Parse pull line
If pos('packet loss',line)>0 Then
Parse var line 'received,'packet.host'%'.
if pos('unknown host',line)>0 Then do
packet.host = 100
'@RXQUEUE /CLEAR'
leave
end
End
packet.host = strip(packet.host)
If packet.host > 99 then currstatus.host = 1 /* down */
else do
currstatus.host = 0
upcount.host = upcount.host + 1
end
curwait = curwait + 1
if curwait > maxwait then curwait = maxwait
if currstatus.host == oldstatus.host then iterate /* same as before? */
if oldstatus.host = -1992 then do
oldstatus.host = currstatus.host
iterate
end
/* say host ':' currstatus() */
oldstatus.host = currstatus.host
beep = 2
curwait = minwait
samesince.host = time('S')
end
Call SysSleep curwait
end
exit
Currstatus:
if currstatus.host = 1 then return 'No Connection'
if currstatus.host = 0 then return 'Connected'
return 'Unknown'
SameSince:
s = time('S') - samesince.host
h = trunc(s / 3600) ; s = s-h*3600
m = trunc(s / 60) ; s = s-m*60
return right(h,2,'0')':'right(m,2,'0')':'right(s,2,'0')
UpCount:
if checkcount.host = 0 then return 0
return trunc(upcount.host/checkcount.host*100)