如何於程式中檢核遠端 IP 主機是否啟動 (Command CHKHOST)?
現在有許多應用軟體均採用 TCP/IP 方式,所以有時候於啟動應用程式前均需要事先
確定遠端主機是否已啟動,所以需要透過 PING 指令來確認,前期電子報是透過 API
來判斷 Local AS/400 主機的IP 狀態,本期介紹透過 PING 指令來判斷主機是否存
在於網路中,我將之簡化為指令 CHKHOST。
File : QCLSRC
Member: CHKHOSTC
Type : CLP
Usage : CRTCLPGM CHKHOSTC
OS version: All version
/* COMMAND CHKHOSTC */
/* TO COMPILE : */
/* CRTCLPGM PGM(XXXX/CHKHOSTC) SRCFILE(XXXX/QCLSRC) */
CHKHOST: PGM PARM(&RMTSYS &INTNETADR)
DCL VAR(&RMTSYS) TYPE(*CHAR) LEN(64)
DCL VAR(&INTNETADR) TYPE(*CHAR) LEN(15)
DCL VAR(&HOST) TYPE(*CHAR) LEN(64)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(150)
DCL VAR(&SUC) TYPE(*DEC) LEN(3 0)
DCL VAR(&SUC_CHR) TYPE(*CHAR) LEN(3)
MONMSG MSGID(TCP3202) EXEC(GOTO CMDLBL(UNKNOWN)) /* +
Unknown host */
IF COND(&RMTSYS *NE *INTNETADR) THEN(DO)
CHGVAR VAR(&HOST) VALUE(&RMTSYS)
PING RMTSYS(&RMTSYS)
ENDDO
ELSE CMD(DO)
CHGVAR VAR(&HOST) VALUE(&INTNETADR)
PING RMTSYS(*INTNETADR) INTNETADR(&INTNETADR)
ENDDO
RCVMSG MSGTYPE(*LAST) MSGDTA(&MSGDTA) MSGID(&MSGID)
IF COND(&MSGID *EQ TCP3210 *AND %BIN(&MSGDTA 9 +
4) *GT 0) THEN(GOTO CMDLBL(OK))
ELSE CMD(GOTO CMDLBL(NOT_OK))
OK: CHGVAR VAR(&SUC) VALUE(%BIN(&MSGDTA 9 4)) /* +
convert to decimal */
CHGVAR VAR(&SUC_CHR) VALUE(&SUC) /* convert to +
character */
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('Connection to host' *BCAT &HOST +
*BCAT 'OK :' *BCAT &SUC_CHR *BCAT '% +
successful') MSGTYPE(*COMP)
RETURN
NOT_OK: SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Host' +
*BCAT &HOST *BCAT 'could not be reached') +
MSGTYPE(*ESCAPE)
UNKNOWN: SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA('Host' +
*BCAT &HOST *BCAT 'unknown.') +
MSGTYPE(*ESCAPE)
END: ENDPGM
File : QCMDSRC
Member: CHKHOST
Type : CMD
Usage : CRTCMD CMD(CHKHOST) PGM(CHKHOSTC)
/* COMMAND CHKHOST */
/* TO COMPILE : */
/* CRTCMD CMD(XXX/CHKHOST) PGM(XXX/CHKHOSTC) + */
/* SRCFILE(XXX/QCMDSRC) */
CHKHOST: CMD PROMPT('Check Host')
PARM KWD(RMTSYS) TYPE(*CHAR) LEN(64) +
SPCVAL((*INTNETADR)) MIN(1) +
PROMPT('Remote System')
PARM KWD(INTNETADR) TYPE(*CHAR) LEN(15) DFT('') +
MIN(0) PMTCTL(INTNETADR) PROMPT('Remote +
internet address')
INTNETADR: PMTCTL CTL(RMTSYS) COND((*EQ *INTNETADR))
DEP CTL(&RMTSYS *EQ *INTNETADR) PARM((INTNETADR))
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期一, 11月 06, 2023
2003-07-21 如何於程式中檢核遠端 IP 主機是否啟動 (Command CHKHOST)?
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言