Since OpenEdge 10.2A, the
_Connect-IPAddress VST displays the client's IP address for ABL remote clients but not local connections. There are no VST's that store the Database Server's Hostname or IP Address.
Other methods of obtaining this information are outlined below. The example 4GL/ABL code provided in this Article may require modification depending on the Operating System commands available and the format of their output.
Finding the Internet Protocol (IP) address of the Database Server with -ipver iPv6In OpenEdge 10.1C and later, the
-ipver IPv6 startup parameter can be used to specify Internet Protocol version 6 network connections for the client session:
- iPv6 allows network connections with IPv6 addresses and mapped IPv4 addresses.
- OpenEdge supports V4 mapped addresses where underlying Operating System support exists: UNIX, Linux, and Windows versions Vista and later.
- Where V4 mapped addresses are supported, a client session can be started with "-ipver IPv6" and connect to a database even when the Database Server is started with "-ipver IPv4" (the default).
The
DB-REMOTE-HOST function can be used to return the IP address of the database when the client session was started with the "-ipver IPv6" startup parameter (OpenEdge 10.1C and later). If the database is not connected using TCP/IP or the -ipver IPv6 startup parameter is not used, the DB-REMOTE-HOST function returns the Unknown value (?).
Example:
MESSAGE USERID 'is connected to Database:' DBNAME 'running on Host:' DB-REMOTE-HOST(DBNAME) VIEW-AS ALERT-BOX.
When multiple databases are connected:
DEFINE VARIABLE i as INT NO-UNDO.
DO i = 1 to NUM-DBS:
MESSAGE USERID 'is connected to Database:' LDBNAME(i) SKIP
'running on Host' DB-REMOTE-HOST(i) SKIP
VIEW-AS ALERT-BOX.
END.
Finding the Internet Protocol (IP) address of the Database Server without -ipver 6If the
client session was not started with "-ipver IPv6", two Steps are necessary:
A. Find the Host Name of the Database Server.If the database was connected using the CONNECT statement, the host name may already have been stored in a variable or preprocessor variable. If the host name was specified in a startup parameter or .pf file, it can be parsed from the value of SESSION:STARTUP-PARAMETERS introduced in Progress 9.1D07. For simplicity, the following examples assume only one connected database:
DEFINE VARIABLE iStartSubstring AS INTEGER NO-UNDO.
DEFINE VARIABLE iAfterSubstring AS INTEGER NO-UNDO.
DEFINE VARIABLE cHost AS CHARACTER NO-UNDO.
DEFINE VARIABLE cCommand AS CHARACTER NO-UNDO.
DEFINE VARIABLE cLine AS CHARACTER NO-UNDO.
iStartSubstring = INDEX (SESSION:STARTUP-PARAMETERS, '-H') + 3.
IF iStartSubstring > 0
THEN DO:
iAfterSubstring = INDEX (SESSION:STARTUP-PARAMETERS, ',', iStartSubstring).
cHost = SUBSTRING (SESSION:STARTUP-PARAMETERS, iStartSubstring, iAfterSubstring - iStartSubstring).
END.
B. Parse the IP Address Use the OS-COMMAND statement to
ping the Server the database was started on to retrieve the IP address from the output. The OS-COMMAND does not return a value, therefore the output of the OS command(s) must be written to a file that can be parsed using:
- OS commands, or
- 4GL/ABL procedure.
1. Parsing ping output using OS commands:On a UNIX system where the
awk utility is available, the following ABL code will write the IP address of the Host to the file ip.txt:
cCommand = "ping -c 1 " + cHost + " | head -n 1| awk '~{print substr($3, 2, length($3)-2)~} > ip.txt'".
OS-COMMAND SILENT VALUE (cCommand).
INPUT FROM "ip.txt".
IMPORT UNFORMATTED cLine.
INPUT CLOSE.
MESSAGE cLine VIEW-AS ALERT-BOX.
2. Parsing ping output using ABL/4GL:
cCommand = "ping -c 1 " + cHost + " > ip.txt".
OS-COMMAND SILENT VALUE (cCommand).
INPUT FROM "ip.txt".
IMPORT UNFORMATTED cLine.
INPUT CLOSE.
iStartSubstring = INDEX ( cLine , "(") + 1.
iAfterSubstring = INDEX ( cLine , ")").
MESSAGE SUBSTRING(cLine, iStartSubstring, iAfterSubstring - iStartSubstring) VIEW-AS ALERT-BOX.
To simply validate the Client's connection:When only needing to validate if the client is connected client/server or shared-memory, the DBPARAM function can be used.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = NUM-ENTRIES(DBPARAM("DICTDB")) TO 1 BY -1:
IF NOT ENTRY(i, DBPARAM("DICTDB")) BEGINS "-S" THEN
NEXT.
MESSAGE
"Database" LDBNAME("DICTDB") "is connected client/server mode." SKIP
"This program must only be used for self-service connections."
VIEW-AS ALERT-BOX INFO BUTTONS OK.
QUIT.
END
3. Using System.Net.NetworkInformation.Ping class: Example:
DEFINE VARIABLE dbhost AS CHARACTER NO-UNDO.
FIND FIRST _DbParams WHERE _DbParams._DbParams-Name = "-H" NO-LOCK NO-ERROR.
IF AVAILABLE (_DbParams) THEN dbhost = _DbParams._DbParams-Value.
DEFINE VARIABLE pingSrv AS System.Net.NetworkInformation.Ping NO-UNDO.
DEFINE VARIABLE pingResult AS System.Net.NetworkInformation.PingReply NO-UNDO.
DEFINE VARIABLE host-ip-address AS CHARACTER NO-UNDO.
pingSrv = NEW System.Net.NetworkInformation.Ping().
pingResult = pingSrv:Send(dbhost).
ASSIGN host-ip-address = pingResult:Address:ToString().
MESSAGE host-ip-address VIEW-AS ALERT-BOX.