home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pingal12.cmd < prev    next >
OS/2 REXX Batch file  |  1993-05-13  |  3KB  |  114 lines

  1. /* PINGAL.CMD: A host alarm for TCP/IP 1.2.1 for OS/2.
  2.  
  3. This Rexx program will ring an alarm whenever the condition of the
  4. specified host has changed (either connection established or lost).
  5. This way, you can monitor the connection, or run it when the connection is
  6. lost, to be notified when the connection is re-established.
  7.  
  8. By turgut Kalfaoglu <turgut@frors12.bitnet>
  9.  
  10. Usage:
  11.   PINGAL hostname1 hostname2 hostnameN
  12. */
  13.  
  14. parse arg hosts
  15. if hosts = '' then hosts = 'FRORS12.circe.fr'
  16.  
  17. /* polling delay.. the program gradually gets 'lazier' to poll
  18.    to reduce load - up to maxwait seconds:
  19. */
  20. minwait = 1
  21. maxwait = 15
  22.  
  23. /* Ping count -- how many times to ping each host, at each interval
  24.   (usually 1-10)
  25. */
  26. pingcount = 10
  27.  
  28. version = 1.1
  29. curwait = minwait
  30. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  31. Call SysLoadFuncs
  32. oldstatus. = -1992
  33. beep = 0
  34. currstatus. = 2
  35. samesince. = time('S')
  36. packet. = 0
  37. upcount. = 0
  38. checkcount. = 0
  39. monstart = time()
  40. '@ECHO OFF'
  41. '@RXQUEUE /CLEAR'
  42. title =  Left('Host',20) Left('Status',15) Left('Since',10)'Packet Loss' ' Uptime'
  43. title2 = Left('----',20) left('------',15) left('-----',10)'-----------' ' ------'
  44. Call SysCLS
  45. z = SysCurPos(2,0)
  46. Say title
  47. Say title2
  48.  
  49. do forever
  50.    z = SysCurPos(0,0)
  51.    Say 'IP Monitor V'version ' started' monstart 'now' time()'   '
  52.    do i=1 to words(hosts)
  53.       host = subword(hosts,i,1)
  54.       blurb = Left(host,20) Left(currstatus(),15) ,
  55.       left(samesince(),10) right(packet.host,5)'%' right(upcount(),10)'%'
  56.       If beep > 0 Then do
  57.          blurb = blurb||'07'x
  58.          beep = beep - 1
  59.       End
  60.  
  61.       z = SysCurPos(i+3,0)
  62.       Say blurb
  63.       '@PING' host '8' pingcount '| RXQUEUE'
  64.       currstatus.host = 2 /* unknown */
  65.       checkcount.host = checkcount.host + 1
  66.       do while queued()>0
  67.          Parse pull line
  68.          If pos('packet loss',line)>0 Then
  69.             Parse var line 'received,'packet.host'%'.
  70.          if pos('unknown host',line)>0 Then do
  71.             packet.host = 100
  72.             '@RXQUEUE /CLEAR'
  73.             leave
  74.          end
  75.       End
  76.       packet.host = strip(packet.host)
  77.       If packet.host > 99 then currstatus.host = 1 /* down */
  78.          else do
  79.            currstatus.host = 0
  80.            upcount.host = upcount.host + 1
  81.          end
  82.       curwait = curwait + 1
  83.       if curwait > maxwait then curwait = maxwait
  84.       if currstatus.host == oldstatus.host then iterate /* same as before? */
  85.       if oldstatus.host = -1992 then do
  86.          oldstatus.host = currstatus.host
  87.          iterate
  88.       end
  89.       /* say host ':' currstatus() */
  90.       oldstatus.host = currstatus.host
  91.       beep = 2
  92.       curwait = minwait
  93.       samesince.host = time('S')
  94.    end
  95.    Call SysSleep curwait
  96. end
  97. exit
  98.  
  99. Currstatus:
  100.     if currstatus.host = 1 then return 'No Connection'
  101.     if currstatus.host = 0 then return 'Connected'
  102.     return 'Unknown'
  103.  
  104. SameSince:
  105.     s = time('S') - samesince.host
  106.     h = trunc(s / 3600) ;    s = s-h*3600
  107.     m = trunc(s / 60)   ;    s = s-m*60
  108.  
  109.     return right(h,2,'0')':'right(m,2,'0')':'right(s,2,'0')
  110.  
  111. UpCount:
  112.     if checkcount.host = 0 then return 0
  113.     return trunc(upcount.host/checkcount.host*100)
  114.