星期二, 11月 07, 2023

2006-07-04 要如何得知AS/400 上 TCP/IP 位址及 port 所連結的 Job ?(Command TCPCNNJOB)


要如何得知AS/400 上 TCP/IP 位址及 port 所連結的 Job ?(Command TCPCNNJOB)

要如何得知AS/400 上 TCP/IP 位址及 port 所連結的 Job ?(TCPCNNJOB)
要得知AS/400 上 TCP/IP 位址及 port 所連結的 Job, 可以使用command NETSTAT 選項 3,

                       Work with TCP/IP Network Status                         
                                                            System:   TEST810  
Select one of the following:                                                   
                                                                               
     1. Work with TCP/IP interface status                                      
     2. Display TCP/IP route information                                       
     3. Work with TCP/IP connection status                                     
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
Selection or command                                                           
===> 3                                                                          

                      Work with TCP/IP Connection Status                       
                                                            System:   TEST810  
Type options, press Enter.                                                     
  3=Enable debug   4=End   5=Display details   6=Disable debug                 
  8=Display jobs                                                               
                                                                               
     Remote           Remote     Local                                         
Opt  Address          Port       Port       Idle Time  State                   
     *                *          as-dtaq-s  026:39:39  Listen                  
     *                *          as-file-s  026:40:52  Listen                  
     *                *          as-netp >  026:39:39  Listen                  
     *                *          as-rmtc >  026:39:38  Listen                  
     *                *          as-sign >  026:39:38  Listen                  
     *                *          4003       000:01:25  Listen                  
     *                *          5000       023:26:16  Listen                  
     172.16.1.1       3246       telnet     000:00:18  Established             
 8   172.16.1.1       3247       telnet     000:00:59  Established             
     172.16.1.1       3248       telnet     000:00:48  Established             
     172.16.1.1       3249       telnet     000:00:25  Established             
     172.16.1.3       3019       telnet     000:06:08  Established             
                                                                       More... 
F3=Exit   F5=Refresh   F9=Command line   F11=Display byte counts   F12=Cancel  
F15=Subset   F22=Display entire field    F24=More keys                         

                         Display Jobs Using Connection                          
                                                             System:   DDSC810  
 Connection type  . . . . . . :   *TCP                                          
 Local address  . . . . . . . :   172.16.15.28                                  
 Local port . . . . . . . . . :   23                                            
 Remote address . . . . . . . :   172.16.1.1                                    
 Remote port  . . . . . . . . :   3247                                          
                                                                                
 Type options, press Enter.                                                     
   5=Work with job                                                              
                                                                                
 Opt  Name        User        Number      Opt  Name        User        Number   
      QPADEV001F  TEST        349792                                            
      QTVDEVICE   QTCP        347585                                            
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                         Bottom 
 F3=Exit   F5=Refresh   F6=Print   F9=Command line   F12=Cancel                 

即可得知現有 IP 及 port 的組合所連結的 Job,但這樣查太慢了, 如果只知 job name 要從上百個
連線手動查, 可能還沒查到網路就斷線了, NETSTAT 是從 網路位址查起, 但是系統並不提供 
output to print or file, 同時也未提供以 Job API 取得相關 Job 的 TCP/IP 資訊, 所以我寫了一
個command TCPCNNJOB 將 TCP connection data output to print or file, 此程式是以 
TCP/IP management APIs (1) by Carsten Flensburg 未範本修改而成,非常感謝 Carsten Flensburg 
的幫助.

 

File  : QRPGLESRC
Member: TCPCNNJOB
Type  : SQLRPGLE
Usage : CRTSQLRPG  OBJ(TCPCNNJOB) SRCFILE(lib/file) SRCMBR(TCPCNNJOB)       


     **
     **  Program . . : TCPCNNJOB
     **  Description : Retrieve TCP/IP connection Job to ptint or file
     **  Author  . . : Vengoal Chang
     **  Published . : AS400ePaper
     **  Date  . . . : April 21, 2006
     **  Based on    : iSeriesnetwork
     **                TCP/IP management APIs (1) by Carsten Flensburg
     **
     **  Program summary
     **  ---------------
     **
     **  Object - User space APIs:
     **    QUSCRTUS       Create user space    Creates a user space in either
     **                                        user domain or system domain.
     **                                        Only user domain user spaces are
     **                                        accessible by the user space APIs.
     **
     **    QUSDLTUS       Delete user space    Deletes the user space specified.
     **
     **    QUSPTRUS       Retrieve pointer to  The address of the first byte
     **                   user space           of the storage allocated by the
     **                                        user space requested is returned.
     **
     **
     **  Communication - TCP/IP management APIs:
     **    QtocRtvTCPA       Retrieve TCP/IP   Retrieves TCP/IPv4 and TCP/IPv6
     **                      attributes        (V5R2) stack attributes.
     **
     **    QtocLstNetCnn     List network      Returns a non-detailed list of
     **                      connections       network connections based on a
     **                                        set of selection criteria defined
     **                                        in the list qualifier parameter.
     **
     **    QtocRtvNetCnnDta  List network      Retrieves detailed information
     **                      connection data   and connection totals for the
     **                                        specified network connection.
     **
     **
     **  Sequence of events:
     **    1. The current operational status of the TCP/IP stack is retrieved
     **       to ensure that TCP/IP connection information is available.
     **
     **    2. A user space is created and a list of the current TCP/IP network
     **       connections is loaded to the user space.
     **
     **    3. For each TCP/IP network connection retrieved from user space a
     **       report line is printed and subsequently the associated network
     **       connection data are retrieved.
     **
     **    4. The based data and list structures are allocated to the storage
     **       adresses defined by the offsets found in the basic and additional
     **       information API formats.
     **
     **    5. A report line is printed for each of the servicing jobs associated
     **       with the current network connection.
     **
     **    6. Finally the user space is deleted, explicitly allocated storage
     **       freed and the program is terminated.
     **
     **
     **  Programmer's notes:
     **    Earliest release program will run: V5R1
     **
     **    The examples here are all retrieving information about TCP/IPv4
     **    stacks and connections. As of V5R2 new API formats are available
     **    for retrieval of similar TCP/IPv6 stack and connection information.
     **
     **    Be careful to allocate sufficient storage for the return structure
     **    of the QtocRtvNetCnnDta API initially. The returned value for bytes
     **    actually available might not include the additional structures,
     **    Socket options and Associated jobs/tasks.
     **
     **    The QtocRtvNetCnnDta API has a reported problem involving a memory
     **    leak. The following PTFs have been released to fix the problem:
     **      R510  SI09122   1000
     **      R520  SI09175   1000
     **
     **
     **  Compile options:
     **
     **    CRTSQLRPG  OBJ(TCPCNNJOB) SRCFILE(lib/file) SRCMBR(TCPCNNJOB)
     **
     **
     **-- Header specifications:  --------------------------------------------**
     H Option( *SrcStmt ) DFTACTGRP(*NO)
     **-- Printer file:  -----------------------------------------------------**
     FQSYSPRT   O    F  132        Printer  InfDs( PrtLinInf )  OflInd( *InOf )
     F                                      UsrOpn
     **-- Printer file information:  -----------------------------------------**
     D PrtLinInf       Ds
     D  PlOvfLin                      5i 0  Overlay( PrtLinInf: 188 )
     D  PlCurLin                      5i 0  Overlay( PrtLinInf: 367 )
     D  PlCurPag                      5i 0  Overlay( PrtLinInf: 369 )
     **-- System information:  -----------------------------------------------**
     D                SDs
     D  PsPgmNam         *Proc

     **-- Global declarations:  ----------------------------------------------**
     D Lix             s             10u 0
     D Dix             s             10u 0
     D BytAlc          s             10u 0
     D UsrSpc          c                   'LSTNETCNN QTEMP'
     **
     DOutFile          DS
     D ##file                        10a
     D ##lib                         10a
     D sqlstm          s            500
     D sqlstm1         s            500
     D tick            s              1    Inz('''')
     D IdleSecs        s             10U 0
     **
     D Time            s              6s 0
     D NbrRcds         s             10u 0
     D TcpCnnStt       s              4a
     D ConOpnTyp       s              3a
     **-- Tcp state table:  --------------------------------------------------**
     D SttTbl          Ds
     D  TcpStt                        5a   Dim( 12 )
     D                               60a   Overlay( SttTbl )
     D                                     Inz( 'LST  SYNR SYNS EST  FIN1 FIN2 +
     D                                           CLO2 CLO1 LACK WAIT CLO  n/s ')
     **-- Open type table:  --------------------------------------------------**
     D OpnTbl          Ds
     D  OpnTyp                        4a   Dim( 3 )
     D                               12a   Overlay( OpnTbl )
     D                                     Inz( 'PSV ACT n/s ' )
     **-- Api error data structure:  -----------------------------------------**
     D ApiError        Ds
     D  AeBytPro                     10i 0 Inz( %Size( ApiError ))
     D  AeBytAvl                     10i 0 Inz
     D  AeMsgId                       7a
     D                                1a
     D  AeMsgDta                    128a
     **
     **-- API Header information:  -------------------------------------------**
     D HdrInf          Ds                  Based( pHdrInf )
     D  HiUsrSpcNamSp                10a
     D  HiUsrSpcLibSp                10a
     **-- User space generic header:  ---------- -----------------------------**
     D UsrSpcHdr       Ds                  Based( pUsrSpc )
     D  UsOfsHdr                     10i 0 Overlay( UsrSpcHdr: 117 )
     D  UsOfsLst                     10i 0 Overlay( UsrSpcHdr: 125 )
     D  UsNumLstEnt                  10i 0 Overlay( UsrSpcHdr: 133 )
     D  UsSizLstEnt                  10i 0 Overlay( UsrSpcHdr: 137 )
     **-- User space pointers:  ----------------------------------------------**
     D pUsrSpc         s               *   Inz( *Null )
     D pHdrInf         s               *   Inz( *Null )
     D pLstEnt         s               *   Inz( *Null )
     **-- TCP/IP attributes:  ------------------------------------------------**
     D TCPA0100        Ds
     D  T1BytRtn                     10u 0
     D  T1BytAvl                     10u 0
     D  T1StkSts                     10u 0
     D  T1ActTim                     10u 0
     D  T1LstStrD                     8a
     D  T1LstStrT                     6a
     D  T1LstEndD                     8a
     D  T1LstEndT                     6a
     D  T1StrJob                     10a
     D  T1StrUsr                     10a
     D  T1StrNbr                      6a
     D  T1StrJobInt                  16a
     D  T1EndJob                     10a
     D  T1EndUsr                     10a
     D  T1EndNbr                      6a
     D  T1EndJobInt                  16a
     D  T1OfsAddInf                  10u 0
     D  T1LenAddInf                  10u 0
     **-- Connection list qualifier:  ----------------------------------------**
     D NCLQ0100        Ds
     D  N1NetCnnTyp                  10a   Inz( '*ALL' )
     D  N1LstRqsTyp                  10a   Inz( '*ALL' )
     D                               12a   Inz( *Allx'00' )
     D  N1LocAdrLow                  10u 0 Inz( 0 )
     D  N1LocAdrUpr                  10u 0 Inz( 0 )
     D  N1LocPortLow                 10u 0 Inz( 0 )
     D  N1LocPortUpr                 10u 0 Inz( 0 )
     D  N1RmtAdrLow                  10u 0 Inz( 0 )
     D  N1RmtAdrUpr                  10u 0 Inz( 0 )
     D  N1RmtPortLow                 10u 0 Inz( 0 )
     D  N1RmmPortUpr                 10u 0 Inz( 0 )
     **-- Connection list entry:  --------------------------------------------**
     D NCNN0100        Ds                  Based( pLstEnt )
     D  C1RmtAdr                     15a
     D                                1a
     D  C1RmtAdrBin                  10u 0
     D  C1LocAdr                     15a
     D                                1a
     D  C1LocAdrBin                  10u 0
     D  C1RmtPort                    10u 0
     D  C1LocPort                    10u 0
     D  C1TcpState                   10u 0
     D  C1IdlTimMs                   10u 0
     D  C1BytIn                      20u 0
     D  C1BytOut                     20u 0
     D  C1ConOpnTyp                  10u 0
     D  C1NetCnnTyp                  10a
     D                                1a
     **-- Following fields were added in V5R2 - do not reference in V5R1:
     D                                1a
     D  C1AscUsrPrf                  10a
     D                                2a
     **-- Socket connection request:  ----------------------------------------**
     D SocCnnRqs       Ds
     D  ScProtocol                   10u 0
     D  ScLocIpAdr                   10u 0
     D  ScLocPortNbr                 10u 0
     D  ScRmtIpAdr                   10u 0
     D  ScRmtPortNbr                 10u 0
     **-- Connection data:  --------------------------------------------------**
     D NCND0100        Ds                  Based( pCnnDta )
     D  D1BytRtn                     10u 0
     D  D1BytAvl                     10u 0
     D  D1CurCnnEst                  10u 0
     D  D1ActOpn                     10u 0
     D  D1PasOpn                     10u 0
     D  D1AttOpnFail                 10u 0
     D  D1EstNxtRes                  10u 0
     D  D1SegSnt                     10u 0
     D  D1SegRtr                     10u 0
     D  D1SegRsn                     10u 0
     D  D1SegRcv                     10u 0
     D  D1SegRcvErr                  10u 0
     D  D1DtgSnt                     10u 0
     D  D1DtgRcv                     10u 0
     D  D1DtgNdlPort                 10u 0
     D  D1DtgNdlOde                  10u 0
     D  D1AddInfOfs                  10u 0
     D  D1AddInfLen                  10u 0
     **
     D NCND0200        Ds                  Based( pCnnDtaInf )
     D  D2Protocol                   10u 0
     D  D2LocIpAdr                   10u 0
     D  D2LocPortNbr                 10u 0
     D  D2RmtIpAdr                   10u 0
     D  D2RmtPortNbr                 10u 0
     D  D2RndTrpTim                  10u 0
     D  D2RndTrpVar                  10u 0
     D  D2OutBytBuf                  10u 0
     D  D2UsrSndNxt                  10u 0
     D  D2SndNxt                     10u 0
     D  D2SndUnack                   10u 0
     D  D2OutPshNbr                  10u 0
     D  D2OutUrgNbr                  10u 0
     D  D2OutWdwNbr                  10u 0
     D  D2IncBytBuf                  10u 0
     D  D2RcvNxt                     10u 0
     D  D2UsrRcvNxt                  10u 0
     D  D2IncPshNbr                  10u 0
     D  D2IncUrgNbr                  10u 0
     D  D2IncWdwNbr                  10u 0
     D  D2TotRtr                     10u 0
     D  D2CurRtr                     10u 0
     D  D2MaxWdwSiz                  10u 0
     D  D2CurWdwSiz                  10u 0
     D  D2LastUpd                    10u 0
     D  D2LastUpdAck                 10u 0
     D  D2CngWdw                     10u 0
     D  D2SlwStrThr                  10u 0
     D  D2MaxSegSiz                  10u 0
     D  D2InzSndSeqNb                10u 0
     D  D2InzRcvSeqNb                10u 0
     D  D2CnnTspLayer                10u 0
     D  D2TcpState                   10u 0
     D  D2CnnOpnTyp                  10u 0
     D  D2IdlTimMs                   10u 0
     D  D2IpOpt                      40a
     D  D2BytIn                      10u 0
     D  D2BytOut                     10u 0
     D  D2SocState                   10u 0
     D  D2SocLstOfs                  10u 0
     D  D2SocEntNbr                  10u 0
     D  D2SocEntLen                  10u 0
     D  D2JobLstOfs                  10u 0
     D  D2JobEntNbr                  10u 0
     D  D2JobEntLen                  10u 0
     **-- Following fields were added in V5R2 - do not reference in V5R1:
     D  D2AscUsrPrf                  10a
     D                                2a
     **-- Socket options list:
     D SocOptLst       Ds                  Based( pSocOptLst )
     D  SoSocOpt                     10u 0
     D  SoOptVal                     10u 0
     **-- Associated jobs/tasks list:
     D JobCnnLst       Ds                  Based( pJobCnnLst )
     D  JcFmtEnt                     10u 0
     D  JcTskNam                     16a
     D  JcJobNam                     10a
     D  JcJobUsr                     10a
     D  JcJobNbr                      6a
     D  JcJobId                      16a
     **-- Create user space: -------------------------------------------------**
     D CrtUsrSpc       Pr                  ExtPgm( 'QUSCRTUS' )
     D  CsSpcNamQ                    20a   Const
     D  CsExtAtr                     10a   Const
     D  CsInzSiz                     10i 0 Const
     D  CsInzVal                      1a   Const
     D  CsPubAut                     10a   Const
     D  CsText                       50a   Const
     **-- Optional 1:
     D  CsReplace                    10a   Const Options( *NoPass )
     D  CsError                   32767a         Options( *NoPass: *VarSize )
     **-- Optional 2:
     D  CsDomain                     10a   Const Options( *NoPass )
     **-- Delete user space: -------------------------------------------------**
     D DltUsrSpc       Pr                  ExtPgm( 'QUSDLTUS' )
     D  DsSpcNamQ                    20a   Const
     D  DsError                   32767a         Options( *VarSize )
     **-- Retrieve pointer to user space: ------------------------------------**
     D RtvPtrSpc       Pr                  ExtPgm( 'QUSPTRUS' )
     D  RpSpcNamQ                    20a   Const
     D  RpPointer                      *
     D  RpError                   32767a         Options( *NoPass: *VarSize )
     **-- Retrieve TCP/IP attributes:  ---------------------------------------**
     D RtvTcpA         Pr                  ExtProc( 'QtocRtvTCPA' )
     D  RtRcvVar                  32767a          Options( *VarSize )
     D  RtRcvVarLen                  10i 0 Const
     D  RtFmtNam                      8a   Const
     D  RtError                   32767a          Options( *VarSize )
     **-- List network connections:  -----------------------------------------**
     D LstNetCnn       Pr                  ExtProc( 'QtocLstNetCnn' )
     D  LcSpcNamQ                    20a   Const
     D  LcFmtNam                      8a   Const
     D  LcCnnQual                    64a   Const
     D  LcCnnQualSiz                 10i 0 Const
     D  LcCnnQualFmt                  8a   Const
     D  LcError                   32767a         Options( *VarSize )
     **-- Retrieve network connection data:  ---------------------------------**
     D RtvCnnDta       Pr                  ExtProc( 'QtocRtvNetCnnDta' )
     D  RcRcvVar                  65535a         Options( *VarSize )
     D  RcRcvVarLen                  10i 0 Const
     D  RcFmtNam                      8a   Const
     D  RcSocCnnRqs                  20a   Const
     D  RcError                   32767a         Options( *VarSize )
     **
     **-- Mainline:  ---------------------------------------------------------**
     **
     C     *Entry        Plist
     c                   Parm                    include           1
     c                   Parm                    OutPut            6
      *                                               OutPut(*Print *File)
     c                   Parm                    OutFile
      *                                               OutPutFile and Library
     c                   Parm                    FileOpt           8
      *                                               File Option(*REPLACE -or- *ADD)
     C                   Time                    Time
     C
     C                   If        OutPut = '*PRINT'
     C                   Except    Header
     C                   EndIf
     **
     C                   CallP     RtvTcpA( TCPA0100
     C                                    : %Size( TCPA0100 )
     C                                    : 'TCPA0100'
     C                                    : ApiError
     C                                    )
     **
     C                   Select
     C                   When      AeBytAvl    > *Zero
     **-- Error occurred...
     C                   Except    NoStack
     **
     C                   When      T1StkSts    = 0             Or
     C                             T1StkSts    = 2
     **-- TCP/IP stack not operational...
     C                   Except    NoStack
     **
     C                   Other
     C                   Eval      BytAlc      = 32767
     C                   Eval      pCnnDta     = %Alloc( BytAlc )
     **
     C                   CallP     CrtUsrSpc( UsrSpc
     C                                      : *Blanks
     C                                      : 65535
     C                                      : x'00'
     C                                      : '*CHANGE'
     C                                      : *Blanks
     C                                      : '*YES'
     C                                      : ApiError
     C                                      )
     **
     C                   CallP     LstNetCnn( UsrSpc
     C                                      : 'NCNN0100'
     C                                      : NCLQ0100
     C                                      : %Size( NCLQ0100 )
     C                                      : 'NCLQ0100'
     C                                      : ApiError
     C                                      )
     **
     C                   If        AeBytAvl    = *Zero
     C                   ExSr      PrcLstEnt
     C                   EndIf
     **
     C                   CallP     DltUsrSpc( UsrSpc
     C                                      : ApiError
     C                                      )
     **
     C                   DeAlloc                 pCnnDta
     **
     C                   If        NbrRcds    =  *Zero  and
     C                             OutPut = '*PRINT'
     C                   Except    NoRcds
     C                   EndIf
     C                   EndSl
     **
     C                   Eval      *InLr       = *On
     C                   Return
      *--------- Start the program ---------------
     C     *inzsr        Begsr

     c                   if        Output = '*FILE' and
     c                             Fileopt = '*REPLACE'
     C                   Exsr      $SQLDrop
     C                   Exsr      $SQLCreate
     c                   endif
     c                   if        Output = '*FILE' and
     c                             Fileopt = '*ADD'
     C                   Exsr      $SQLCreate
     c                   endif

     c                   if        OutPut = '*PRINT'
     c                   Open      Qsysprt
     c                   endif
     C                   Endsr
     **
     **-- Process list entries:  ---------------------------------------------**
     C     PrcLstEnt     BegSr
     **
     C                   CallP     RtvPtrSpc( UsrSpc
     C                                      : pUsrSpc
     C                                      )
     **
     C                   Eval      pHdrInf     = pUsrSpc + UsOfsHdr
     C                   Eval      pLstEnt     = pUsrSpc + UsOfsLst
     **
     C                   For       Lix         = 1  to UsNumLstEnt
     **
     C                   If        Include = 'Y' OR
     C                             (Include = 'N' and C1TcpState <> 0)
     C                   Eval      TcpCnnStt  =  TcpStt(C1TcpState  + 1)
     C                   If        OutPut = '*PRINT'
     C                   ExSr      PrtCnnDtl
     C                   EndIf
     **
     C                   Select
     C                   When      C1NetCnnTyp = '*TCP'
     C                   Eval      ScProtocol  = 1
     **
     C                   When      C1NetCnnTyp = '*UDP'
     C                   Eval      ScProtocol  = 2
     **
     C                   Other
     C                   Eval      ScProtocol  = 0
     C                   EndSl
     C
     C                   If        ScProtocol  > 0
     **
     C                   Eval      ScLocIpAdr  = C1LocAdrBin
     C                   Eval      ScLocPortNbr= C1LocPort
     C                   Eval      ScRmtIpAdr  = C1RmtAdrBin
     C                   Eval      ScRmtPortNbr= C1RmtPort
     **
     C                   if        C1IdlTimMs  > 0
     C                   Eval      IdleSecs  = C1IdlTimMs / 1000
     C                   Else
     C                   Eval      IdleSecs  = 0
     C                   EndIf

     C                   DoU       D1BytAvl   <= BytAlc
     **
     C                   If        D1BytAvl    > BytAlc
     C                   Eval      BytAlc      = D1BytAvl
     C                   Eval      pCnnDta     = %ReAlloc( pCnnDta: BytAlc )
     C                   EndIf
     **
     C                   CallP     RtvCnnDta( NCND0100
     C                                      : BytAlc
     C                                      : 'NCND0200'
     C                                      : SocCnnRqs
     C                                      : ApiError
     C                                      )
     C                   EndDo
     **
     C                   If        AeBytAvl    = *Zero
     C                   ExSr      PrcDtaEnt
     C                   EndIf
     C                   EndIf
     C                   EndIf
     **
     C                   If        Lix         < UsNumLstEnt
     C                   Eval      pLstEnt     = pLstEnt + UsSizLstEnt
     C                   EndIf
     C                   EndFor
     **
     C                   EndSr
     **-- Process data list entries:  ----------------------------------------**
     C     PrcDtaEnt     BegSr
     **
     C                   Eval      pCnnDtaInf  = pCnnDta + D1AddInfOfs
     **
     **-- Socket options:
     C                   Eval      pSocOptLst  = pCnnDta + D2SocLstOfs
     C                   For       Dix         = 1  to D2SocEntNbr
     **
     **--
     C                   If        Dix         < D2SocEntNbr
     C                   Eval      pSocOptLst  = pSocOptLst + D2SocEntLen
     C                   EndIf
     C                   EndFor
     **
     **-- Associated jobs:
     C                   Eval      pJobCnnLst  = pCnnDta + D2JobLstOfs
     **
     C                   For       Dix         = 1  to D2JobEntNbr
     **
     C                   If        JcFmtEnt    = 1
     C                   If        OutPut = '*FILE'
     C                   Exsr      $SQLAddRec
     C                   Else
     C                   ExSr      PrtJobDtl
     C                   EndIf
     C                   EndIf
     **
     C                   If        Dix         < D2JobEntNbr
     C                   Eval      pJobCnnLst  = pJobCnnLst + D2JobEntLen
     C                   EndIf
     C                   EndFor
     **
     C                   EndSr
     **-- Print connection detail line:  -------------------------------------**
     C     PrtCnnDtl     BegSr
     **
     C                   If        PlCurLin    > PlOvfLin - 3
     C                   Except    Header
     C                   EndIf
     **
     C                   Eval      TcpCnnStt  =  TcpStt(C1TcpState  + 1)
     C                   Eval      ConOpnTyp  =  OpnTyp(C1ConOpnTyp + 1)
     **
     C                   Eval      NbrRcds    =  NbrRcds + 1
     C                   Except    CnnDtl
     **
     C                   EndSr
     **-- Print connection job detail line:  ---------------------------------**
     C     PrtJobDtl     BegSr
     **
     C                   If        PlCurLin    > PlOvfLin - 2
     C                   Except    Header
     C                   EndIf
     **
     C                   Except    JobDtl
     **
     C                   EndSr
      *---------------------------------------------------------------
     C* SQL Create Table
      *---------------------------------------------------------------
     C     $SQLCreate    Begsr

     C                   eval      sqlStm = 'create table ' +
     C                                %trim(##lib) + '/' +
     C                                %trim(##File) + '('    +
     C                                ' LclAddr    CHAR(15)      NOT NULL,' +
     C                                ' RmtAddr    CHAR(15)      NOT NULL,' +
     C                                ' LclPort    NUMERIC(5,0)  NOT NULL,' +
     C                                ' RmtPort    NUMERIC(5,0)  NOT NULL,' +
     C                                ' JcJobNam   CHAR(10)      NOT NULL,' +
     C                                ' JcJobUsr   CHAR(10)      NOT NULL,' +
     C                                ' JcJobNbr   CHAR(6)       NOT NULL,' +
     C                                ' TcpCnnStt  CHAR(4)       NOT NULL,' +
     C                                ' IdleSecs   NUMERIC(10,0) NOT NULL,' +
     C                                ' OutPutTime TIMESTAMP +
     C                                  NOT NULL WITH DEFAULT ' +
     C                                 ') '

     c/Exec Sql
     c+    declare s statement
     c/End-Exec

     c/Exec Sql
     c+    prepare s from :sqlStm
     c/End-Exec

     c/Exec Sql
     c+    execute s
     c/End-Exec

     C                   Endsr
      *---------------------------------------------------------------
     C* SQL Drop Table
      *---------------------------------------------------------------
     C     $SQLDrop      Begsr

     C                   eval      sqlStm = 'drop table ' +
     C                                %trim(##lib) + '/' +
     C                                %trim(##File)

     C/exec SQL
     C+  Set option commit = *none
     C/end-EXEC

     c/Exec Sql
     c+    declare d statement
     c/End-Exec

     c/Exec Sql
     c+    prepare d from :sqlStm
     c/End-Exec

     c/Exec Sql
     c+    execute d
     c/End-Exec

     C                   Endsr
      *---------------------------------------------------------------
     C* SQL Add to Table
      *---------------------------------------------------------------
     C     $SQLAddRec    Begsr

     C     X'00':' '     xlate     c1locadr      c1locadr
     C     X'00':' '     xlate     c1rmtadr      c1rmtadr

     C                   eval      sqlStm1 = 'insert into ' +
     C                                %trim(##lib) + '/' +
     C                                %trim(##File) + '('    +
     C                                ' LclAddr,' +
     C                                ' RmtAddr,' +
     C                                ' LclPort,' +
     C                                ' RmtPort,' +
     C                                ' JcJobNam,' +
     C                                ' JcJobUsr,' +
     C                                ' JcJobNbr,' +
     C                                ' TcpCnnStt,'+
     C                                ' IdleSecs'  +
     C                                 ') Values('+ tick +
     c                                c1locadr + tick + ', ' + tick +
     c                                c1rmtadr + tick + ', ' +
     c                                %editc(c1locport : '3') + ', ' +
     c                                %editc(c1rmtport : '3') + ', ' +tick +
     c                                JcJobNam + tick + ', ' + tick +
     c                                JcJobUsr + tick + ', ' + tick +
     c                                JcJobNbr + tick + ', ' + tick +
     c                                TcpCnnStt + tick + ', ' +
     c                                %editc(idlesecs: '3')+ ')'

     c/Exec Sql
     c+    declare w statement
     c/End-Exec

     c/Exec Sql
     c+    prepare w from :sqlStm1
     c/End-Exec

     c/Exec Sql
     c+    execute w
     c/End-Exec

     C                   Endsr
      *---------------------------------------------------------------
     **-- Print file definition:  --------------------------------------------**
     OQSYSPRT   EF           Header         2  3
     O                       UDATE         Y      8
     O                       Time                18 '  :  :  '
     O                                           75 'Print TCP/IP connection -
     O                                              status'
     O                                          107 'Program:'
     O                       PsPgmNam           118
     O                                          126 'Page:'
     O                       PAGE             +   1
     OQSYSPRT   EF           Header         1
     O                                           14 'Remote address'
     O                                           25 '- Port'
     O                                           40 'Local address'
     O                                           52 '- Port'
     O                                           58 'Type'
     O                                           70 'Open'
     O                                           76 'State'
     O                                           90 'Idle time ms'
     O                                          111 'Bytes in'
     O                                          132 'Bytes out'
     **
     OQSYSPRT   EF           CnnDtl         1
     O                       C1RmtAdr            15
     O                       C1RmtPort     3     25
     O                       C1LocAdr            42
     O                       C1LocPort     3     52
     O                       C1NetCnnTyp         64
     O                       ConOpnTyp           69
     O                       TcpCnnStt           76
     O                       C1IdlTimMs    3     90
     O                       C1BytIn       3    111
     O                       C1BytOut      3    132
     **
     OQSYSPRT   EF           JobDtl         1
     O                                           22 'Connection job name:'
     O                       JcJobNam            33
     O                                           41 '- user:'
     O                       JcJobUsr            52
     O                                           61 '- number:'
     O                       JcJobNbr            68
     **
     OQSYSPRT   EF           NoStack     1
     O                                           26 '(TCP/IP stack not active)'
     OQSYSPRT   EF           NoRcds      1
     O                                           26 '(No entries found)'




File  : QCMDSRC
Member: TCPCNNJOB
Type  : CMD
Usage : CRTCMD CMD(TCPCNNJOB) PGM(TCPCNNJOB)        


/*  ===============================================================  */
/*  = Command....... TCPCNNJOB                                    =  */
/*  = CPP........... TCPCNNJOB                                    =  */
/*  = Description... Output TCP connection job information to     =  */
/*  =                print or file                                =  */
/*  =                                                             =  */
/*  = CrtCmd      Cmd( TcpCnnJob )                                =  */
/*  =             Pgm( TcpCnnJob  )                               =  */
/*  =             SrcFile( YourSourceFile )                       =  */
/*  ===============================================================  */
/*  = Date  : 2006/04/26                                          =  */
/*  = Author: Vengoal Chang                                       =  */
/*  ===============================================================  */
             CMD        PROMPT('TCPCnnJob - OutPut for TCP job')
             PARM       KWD(LISTEN) TYPE(*CHAR) LEN(1) RSTD(*YES) +
                          DFT(N) VALUES(Y N) PROMPT('Include +
                          Listening Ports?' 1)
             PARM       KWD(OUTPUT) TYPE(*CHAR) LEN(6) RSTD(*YES) +
                          DFT(*PRINT) VALUES(*PRINT *FILE) +
                          PROMPT('Output' 2)
             PARM       KWD(FILE) TYPE(FILE) PMTCTL(ISFILE) +
                          PROMPT('File Name' 3)
             PARM       KWD(FILEOPT) TYPE(*NAME) LEN(8) DFT(*ADD) +
                          SPCVAL((*ADD) (*REPLACE)) PMTCTL(ISFILE) +
                          PROMPT('File Option' 4)
 FILE:       QUAL       TYPE(*NAME) LEN(10) DFT(TCPCNNJOB)
             QUAL       TYPE(*NAME) LEN(10) DFT(QTEMP) +
                          SPCVAL((*LIBL)) PROMPT('Library')
 ISFILE:     PMTCTL     CTL(OUTPUT) COND((*EQ '*FILE'))
 
 
 Run sample:
 TCPCNNJOB, 按 F4:
                   TCPCnnJob - OutPut for TCP job (TCPCNNJOB)             
                                                                         
Type choices, press Enter.                                               
                                                                         
Include Listening Ports? . . . .   N             Y, N                    
Output . . . . . . . . . . . . . > *FILE         *PRINT, *FILE           
File Name  . . . . . . . . . . .   TCPCNNJOB     Name                    
  Library  . . . . . . . . . . .     QTEMP       Name, *LIBL             
File Option  . . . . . . . . . .   *ADD          Name, *ADD, *REPLACE    

按 Enter,此時 QTEMP 下會有 TCPCNNJOB PF, RUNQRY *N TCPCNNJOB 即可以 Job name 查詢



沒有留言: