Consultor Eletrônico



Kbase P1344: How to Detect from the 4GL Whether a Machine is Alive
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/21/2010
Status: Unverified

GOAL:

How to Detect from the 4GL Whether a Machine is Alive

GOAL:

How to Detect from the 4GL Whether a Machine is Attached to the Network

FACT(s) (Environment):

Progress 9.x
Windows 32 Intel
Windows NT 32 Intel/Windows 2000

FIX:

There is no direct way to detect that from the 4GL.

However you can use the following example to build your own code.
It runs the OS "ping" command, and detects a positive response.

The -w parameter specifies how long "ping" should wait before timing out.
Therefore, if the machine is connected to the network, "ping" will return almost immediately and the whole procedure will be very short; if the machine is disconnected or shut down, "ping" will time out after 5 seconds.

The -w parameter specifies that only one attempt should be done to contact the destination machine.

Input parameter pIpAddress will be a string containing the host name or IP address, exactly as you would enter it with the "ping" command from the Command Prompt.

Output parameter pAlive is YES if the machine responded, NO if it did not.

/* ping.p.
Can be easily turned into an internal procedure. */
DEFINE INPUT PARAMETER pIpAddress AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER pAlive AS LOGICAL NO-UNDO.

DEFINE VARIABLE inputLine AS LOGICAL NO-UNDO.

INPUT THROUGH VALUE("ping " + pIpAddress + " -w 5 -n 1").
mainBlock:
REPEAT:
IMPORT UNFORMATTED inputLine.
IF inputLine MATCHES "*Reply*from*bytes*time*" THEN DO:
pAlive = YES.
RETURN.
END.
END.
INPUT CLOSE.
ASSIGN pAlive = NO.
RETURN.