Kbase P25634: How to ping an IP address of a host from 4GL?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  20/05/2010 |
|
Status: Verified
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
GOAL:
How to ping an IP address of a host from 4GL?
GOAL:
How to use the INPUT THROUGH statement to ping an IP address of a host?
FACT(s) (Environment):
Progress 9.x
OpenEdge Category: Language (4GL/ABL)
Windows
OpenEdge 10.x
FIX:
There is no direct way to detect this from the 4GL. However you can use the following example to build your own code, which runs the OS "ping" command and detects a positive response.
The following code sample uses the 4GL INPUT THROUGH statement to invoke the OS level PING utility and parses the results to determine whether the host is online or not. This code was developed and tested on a Microsoft Windows XP operating system. It determines that the host is online and that the IP address is a valid one if it encounters the word "Reply" in the output of the ping command used. This is so because a one line of the output from a successful ping command on Windows XP looks like this:
"Reply from 172.16.0.199: bytes=32 time=1ms TTL=255"
You may have to modify the "target" parameter of the INDEX function in this code to reflect the string returned by your operating system. Indeed you may also have to modify the value of the cCommandLine variable to reflect your operating system PING utility syntax :
DEFINE VARIABLE cCommandLine AS CHARACTER NO-UNDO.
DEFINE VARIABLE cImportedLine AS CHARACTER NO-UNDO.
DEFINE VARIABLE lValidAddress AS LOGICAL NO-UNDO.
/*
The -w parameter specifies how long "ping" should wait before timing out. If the machine being queried 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 timeout after 10 seconds in this example.
The -n parameter specifies only one attempt to contact the destination machine in this example.
*/
ASSIGN
cCommandLine = "c:\windows\system32\ping 1712.16.0.199 -n 1 -w 10"
lValidAddress = FALSE.
INPUT THROUGH value(cCommandLine).
REPEAT:
IMPORT UNFORMATTED cImportedLine.
IF INDEX (cImportedLine, "Reply") > 0 THEN DO:
lValidAddress = TRUE.
LEAVE.
END.
END.
INPUT CLOSE.
IF lValidAddress THEN
DO:
/* Execute valid IP and machine online code here */
END.
ELSE
DO :
/* Execute invalid IP or machine offline code here */
END.