QuikCode Language
Netping
This program monitors a server and sounds an alarm when the connection is broken...
Support:   MS DOS  MS Win  Linux  Stratus VOS 
 
 

****************************************************************************
* Program: netping.q v1.3                                                  *
* Written: 06/26/2007                                                      *
* Purpose: Pings a server at a specified time interval and sounds an alarm *
*          when connection errors are detected. Network errors are written *
*          to a log file.                                                  *
* Syntax.: quikcode.exe netping.q [Enter Key]                              *
*                                                                          *
* Equates: SERVER ---------> IP Address of server to ping.                 *
*          LOG-FILE -------> Log file to record network errors.            *
*          PING-TIME ------> Default time interval to ping server.         *
*          ALERT-TIME -----> Time interval to ping server during an alert. *
*          ALERT-MUTE -----> Mute after contiguous number of alerts.       *
*                            (All sounds are muted if set to 0)            *
*          ALERT-MINIMIZE -> Minimize after contiguous number of alerts.   *
*                            (Will not minimize window if set to 0)        *
*          WINDOW-HIDE ----> If set to 'Y', window will only appear during *
*                            timeout, or connection alerts.                *
*          UP-WAV ---------> Connection up wav sound file.                 *
*          DOWN-WAV -------> Connection down wav sound file.               *
*          TIMEOUT-WAV ----> Connection Timeout wav sound file.            *
*                                                                          *
* Notes..: - Replace SERVER equate value with YOUR desired server Domain   *
*            Name or IP address.                                           *
*          - Server must be pingable, otherwise NetPing will NOT work.     *
*          - Kill using Windows task manager when window is hidden.        *
*          - To turn logging off, set LOG-FILE equate to '' or spaces.     *   
****************************************************************************

* These options reduce program memory requirements
option equmax          = 50                   * Max number of pgm equates
option labmax          = 20                   * Max number of pgm labels
option stmtmax         = 300                  * Max number of pgm statements
option strmax          = 60                   * Max number of pgm strings
option wstsize         = 125                  * Working Storage record size
option ifasize         = 200                  * Input File A record size
option ofasize         = 70                   * Output File A record size

* User configurable equates  
equate SERVER            to 'yahoo.com'       * <-- DOMAIN NAME or IP ADDRESS HERE
equate LOG-FILE          to 'netping.log'     * Append errors to log file
equate PING-TIME         to 60000             * 1 Minute default ping interval
equate ALERT-TIME        to 15000             * 15 Second alert ping interval
equate ALERT-MUTE        to 10                * Mute after 10 contiguous alerts
equate ALERT-MINIMIZE    to 15                * Minimize after 15 contiguous alerts
equate WINDOW-HIDE       to 'N'               * Hide window if connected, otherwise
                                              * just minimize the window.
equate UP-WAV            to 'net_up.wav'      * Wav file -> Network up
equate DOWN-WAV          to 'net_dn.wav'      * Wav file -> Network down
equate TIMEOUT-WAV       to 'net_to.wav'      * Wav file -> Network timeout

* Leave these equates intact
equate VERSION           to 'v1.3'            * NetPing version number
equate BELL              to x'07'             * Ring the PC bell
equate WHITE-ON-BLACK    to 15                * White text on black background
equate RED-ON-BLACK      to 12                * Red text on black background
equate YELLOW-ON-BLACK   to 14                * Yellow text on black background
equate GREEN-ON-BLACK    to 10                * Green text on black background
equate DKRED-ON-BLACK    to 4                 * Dark Red text on black background
equate DKYELLOW-ON-BLACK to 6                 * Dark Yellow text on black background
equate DKGREEN-ON-BLACK  to 2                 * Dark Green text on black background
equate GRAY-ON-BLACK     to 7                 * Gray text on black background
equate UP                to 'U'               * Connection is Up
equate DOWN              to 'D'               * Connection is Down
equate TIMEOUT           to 'T'               * Connection Timed out
equate HIDE              to 0                 * Hide window
equate SHOW              to 8                 * Show window
equate MINIMIZE          to 6                 * Minimize window
equate MAXIMIZE          to 10                * Maximize window

* Working Storage equates
equate idx               to wst1-2-i          * General purpose index
equate idx2              to wst3-4-i          * General purpose index
equate sleep-millis      to wst5-8-L          * Sleep delay in milliseconds
equate error-cnt         to wst9-10           * Counter of contiguous errors
equate net-status-cd     to wst11             * (D)own, (U)p, (T)imeout
equate net-timeouts      to wst12-18          * Total Network Timeouts Detected
equate net-timeout-dt    to wst19-28          * Last Network Timeout Date
equate net-timeout-tm    to wst29-39          * Last Network Timeout Time
equate net-disconnects   to wst40-46          * Total Network Disconnects Detected
equate net-disconnect-dt to wst47-56          * Last Network Disconnect Date
equate net-disconnect-tm to wst57-67          * Last Network Disconnect Time
equate net-connects      to wst68-74          * Total Network Connects Detected
equate net-connect-dt    to wst75-84          * Last Network Connect Date
equate net-connect-tm    to wst85-95          * Last Network Connect Time
equate start-dt          to wst96-105         * NetPing Start Date
equate start-tm          to wst106-116        * NetPing Start Time
equate logging-sw        to wst117            * Log to file switch (Y/N)

cls                                           * Clear the screen
cursor off                                    * Cursor is invisible
scroll off
set windowtitle          to 'NetPing ' VERSION '  to  ' SERVER  * Set Window Title
set windowsize           to 5 51              * Set Window Size
move PING-TIME           to sleep-millis
move 0                   to error-cnt
move 0                   to net-timeouts
move 0                   to net-disconnects
move 0                   to net-connects
move date                to start-dt
move time                to start-tm     
move start-dt            to ofa1-10
move start-tm            to ofa12-22
move '- NetPing ' VERSION ' started.  Server: ' SERVER to ofa24
if LOG-FILE = ''
  or LOG-FILE = spaces
  move 'N'               to logging-sw
else
  move 'Y'               to logging-sw
  open ofa LOG-FILE textappend       
  if ofa is open
    write ofa             * Write netping started to log file
    close ofa.


* Main Loop
100 perform 200               * Ping the SERVER
sleep sleep-millis        * Sleep between pings
go to 100


* Ping the SERVER
200 perform 700               * Animate NetPing Header
open ifa 'ping ' SERVER ' -n 1 -l 1' pipe    * Ping server using Pipe I/O
if ifa is not open        * This should never happen!
  color YELLOW-ON-BLACK
  display ' Unable to execute PING command!  Program netping.q will stop.' BELL
  sleep 10000
  end.
210 read ifa at eof 220
move 1                   to idx
findi 'Request timed out' in ifa by idx
if idx > 0                * Server didn't respond soon enough
  perform 300             * Connection Timeout Alert
  go to 230.
move 1                   to idx
findi 'Reply from' in ifa by idx
if idx = 0
  go to 210.
findi 'time=' in ifa by idx
if idx > 1                * Server responded
  move idx               to idx2
  find space in ifa by idx2
  move spaces            to ifa2-4(idx2) * Remove TTL
  perform 500             * Connection is up.
  go to 230.
220 perform 400               * Connection Down Alert
230 close ifa                 * Close Pipe
299 exit


* Connection Timeout Alert
300 if ALERT-MINIMIZE > 0
  if error-cnt = ALERT-MINIMIZE  
  set windowstate        to MINIMIZE. * Minimize Window

if net-status-cd <> TIMEOUT
  move TIMEOUT           to net-status-cd
  move ALERT-TIME        to sleep-millis
  set windowstate        to MAXIMIZE  * Maximize the window
  set windowstate        to SHOW      * Show the window
  move date              to ofa
  move time1-11          to ofa12-22
  move '- Timeout detected' to ofa24-41
  if logging-sw = 'Y'
    open ofa LOG-FILE textappend      * Write errors to log file  
    if ofa is open
      write ofa
      close ofa.

if ALERT-MUTE > 0
  if error-cnt <= ALERT-MUTE
  playsound TIMEOUT-WAV nowait.

add 1                    to error-cnt
add 1                    to net-timeouts
move date                to net-timeout-dt
move time                to net-timeout-tm
perform 600               * Display NetPing Statistics
399 exit                  


* Connection Down Alert
400 if ALERT-MINIMIZE > 0
  if error-cnt = ALERT-MINIMIZE  
  set windowstate        to MINIMIZE. * Minimize Window

if net-status-cd <> DOWN
  move DOWN              to net-status-cd
  move ALERT-TIME        to sleep-millis
  set windowstate        to MAXIMIZE  * Maximize the window
  set windowstate        to SHOW      * Show the window
  move date              to ofa
  move time              to ofa12-22
  move '- Disconnected ' to ofa24-41
  if logging-sw = 'Y'
    open ofa LOG-FILE textappend      * Write errors to log file
    if ofa is open
      write ofa
      close ofa.
if ALERT-MUTE > 0
  if error-cnt <= ALERT-MUTE
  playsound DOWN-WAV nowait.

add 1                    to error-cnt
add 1                    to net-disconnects
move date                to net-disconnect-dt
move time                to net-disconnect-tm
perform 600               * Display NetPing Statistics
499 exit                 


* Connection Up Notification
500 if net-status-cd = UP
  color GREEN-ON-BLACK
  cursor 2 26
  display ifa6-10(idx) noskip
  exit.

move UP                  to net-status-cd
move PING-TIME           to sleep-millis
set windowstate          to MAXIMIZE  * Maximize the window
set windowstate          to SHOW      * Show the window
move date                to net-connect-dt
move time                to net-connect-tm
move 0                   to error-cnt
add 1                    to net-connects
perform 600               * Display NetPing Statistics
if ALERT-MUTE > 0
  playsound UP-WAV nowait.
move date                to ofa
move time1-11            to ofa12-22
move '- Connected '      to ofa24
move ifa6-10(idx)        to ofa36-40   
move ' '                 to ofa41
if ALERT-MINIMIZE > 0
  sleep 10000
  set windowstate        to MINIMIZE  * Minimize Window
  if WINDOW-HIDE = 'Y'
    set windowstate      to HIDE.     * Hide Window
if logging-sw = 'Y'
  open ofa LOG-FILE textappend        * Write errors to log file
  if ofa is open
    write ofa
    close ofa.
599 exit


* Display NetPing Statistics
600 cursor 2 1  
color GRAY-ON-BLACK
display 'Status.....:'
display 'Disconnects:           Last:'
display 'Timeouts...:           Last:'
display 'Connects...:           Last:' noskip

if net-status-cd = DOWN
  color RED-ON-BLACK
  cursor 2 14
  display 'Disconnected     ' noskip
else
  color GRAY-ON-BLACK.

cursor 3 14
display net-disconnects noskip
cursor 3 30
display net-disconnect-dt ' ' net-disconnect-tm noskip

if net-status-cd = TIMEOUT
  color YELLOW-ON-BLACK
  cursor 2 14
  display 'Timeout detected ' noskip
else
  color GRAY-ON-BLACK.

cursor 4 14
display net-timeouts  noskip
cursor 4 30
display net-timeout-dt ' ' net-timeout-tm noskip

if net-status-cd = UP
  color GREEN-ON-BLACK
  cursor 2 14
  display 'Connected - ' noskip
  display ifa6-10(idx) noskip
else
  color GRAY-ON-BLACK.

cursor 5 14     
display net-connects noskip
cursor 5 30
display net-connect-dt ' ' net-connect-tm noskip
699 exit

* Animate NetPing Header
700 move 0                   to idx
cursor 1 9
color WHITE-ON-BLACK
display 'N e t P i n g   S t a t i s t i c s' noskip
710 cursor 1 5
color GREEN-ON-BLACK
display '((' noskip
cursor 1 46
color GREEN-ON-BLACK
display '))' noskip
sleep 40
cursor 1 5
color DKGREEN-ON-BLACK
display '((' noskip
cursor 1 46
color DKGREEN-ON-BLACK
display '))' noskip
sleep 40
cursor 1 3
color YELLOW-ON-BLACK
display '((' noskip
cursor 1 48
color YELLOW-ON-BLACK
display '))' noskip
sleep 40
cursor 1 3
color DKYELLOW-ON-BLACK
display '((' noskip
cursor 1 48
color DKYELLOW-ON-BLACK
display '))' noskip
sleep 40
cursor 1 1
color RED-ON-BLACK
display '((' noskip
cursor 1 50
color RED-ON-BLACK
display '))' noskip
sleep 40
cursor 1 1
color DKRED-ON-BLACK
display '((' noskip
cursor 1 50
color DKRED-ON-BLACK
display '))' noskip
sleep 40
add 1 to idx
if idx < 3
  go to 710.
cursor 1 9
color GRAY-ON-BLACK
display 'N e t P i n g   S t a t i s t i c s' noskip
799 exit