ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

System IP address

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • System IP address

    How do I retrieve the IP address of a machine via a CL program?

    I checked RTVJOBA but it's not there, so I checked RTVNETA and it's not there either.
    Everyday's a school day, what grade are you in?

  • #2
    Re: System IP address

    You could convert this to CL or use as a procedure
    PHP Code:
          *==========================================================
          * 
    To Compile:
          *
          *    
    CRTBNDRPG  PGM(XXX/RTVIPADR1)
          *
          * Function: 
    Retrieve IP address of PC
          
    *
          *==========================================================
         
    H DFTACTGRP(*NOBNDDIR('QC2LE')
         
    D RtvIpAdr        PR            20a
         D  Device                       10a   
    CONST
          *
         
    D I_Net_Adr       S             16a
          
    *
         
    D                SDS
         D  Device               244    253
          
    *---------------------------------------------------------
          * 
    Retrieve IP Address
         C                   
    Eval      I_Net_Adr   RtvIpAdr(Device)
         
    C                   Eval      I_Net_Adr   = %trim(I_Net_Adr)

         
    C     I_Net_Adr     Dsply
         C                   
    Eval      *Inlr = *On
          
    *---------------------------------------------------------
          *    
    RtvIpAdr Subprocedure To Retrieve PC's IP Address
          *---------------------------------------------------------
         P RtvIpAdr        B                   Export
         D RtvIpAdr        PI            20A
         D  Inp_Device                   10A   Const
         D Apierr          DS
         D  Bytprv                 1      4B 0 Inz(216)
         D  Bytavl                 5      8B 0 Inz
         D  Errid                  9     15A   Inz
         D  Rsvd                  16     16A   Inz
         D  Errdta                17    216A   Inz
         D Net_Address     S             20A   INZ
         D Format          S              8A   Inz('
    DEVD0600')
         D Rcvar           S           5000A   Inz
         D Varlen          S              4B 0 Inz(5000)
         C                   Eval      Device = Inp_Device
         C                   Call      '
    QDCRDEVD'
         C                   Parm                    Rcvar
         C                   Parm                    Varlen
         C                   Parm                    Format
         C                   Parm                    Device
         C                   Parm                    Apierr
         C                   If        BytAvl = 0
         C                   Eval      Net_Address = %Subst(Rcvar:877:16)
         C                   Endif
         C                   Return    Net_Address
         P RtvIpAdr        E 
    Attached Files
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: System IP address

      Jamie, sorry, I should have been more specific. by machine I meant the as400 the program is running on.
      Everyday's a school day, what grade are you in?

      Comment


      • #4
        Re: System IP address

        Crap... do you need the IP or would the system name work?

        PHP Code:
        pgm                                             
                                                        
            dcl 
        &sysname *char 8                        
                                                        
                     RTVNETA    SYSNAME
        (&SYSNAME)       
                                                        
          
        endpgm 
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: System IP address

          Ip.
          Everyday's a school day, what grade are you in?

          Comment


          • #6
            Re: System IP address

            This is what Ive read....

            you can use the code above to get system name
            then add on the network id

            then ping....

            receive the message back to get ip.

            doesnt sound fun ! the data is entered in the system host table..
            I just cant find a way to get it out.

            jamie
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: System IP address

              here it is

              PHP Code:
              SELECT FROM QATOCHOST ORDER BY HOSTNME1INTERNET 
              From my second favorite site http://www.think400.dk/

              PHP Code:
              The calling program
                   
              **  Program . . : CBX109T
                   
              **  Description Get file field value by key Test
                   
              **
                   **  
              Program directions
                   
              **  ------------------
                   **
                   **  
              This test program retrieves field values from the TCP/IP host table
                   
              **  which is stored in a physical file named QATOCHOST in QUSRSYS.
                   **
                   **  
              Go CFGTCP option 10 allow you to examine the current entries in this
                   
              **  table. If you want, or if requiredplease change the key value from
                   
              **  '127.0.0.1' to another existing entry in the table.  Please also
                   
              **  check that you have sufficient authority to the table prior to
                   
              **  running this test program.
                   **
                   **  
              Another option would be to replace the file namefield name and key
                   
              **  value specified in the example below to values of your own choice.
                   **
                   **  
              This test program presents the retrieved field values using the DSPLY
                   
              **  facility.  You could also simply start a debug session against this
                   
              **  program and step through the code linesto watch the process as it
                   
              **  unfolds.
                   **
                   **  
              When the debug session is positioned on a GetFldVal() procedure
                   
              **  statement you can use F22 to step into the subprocedure and examine
                   
              **  the statements executed there.  The F10 step instruction also applies
                   
              **  while in the subprocedure.
                   **
                   **
                   **  
              Compile options required:
                   **    
              CrtRpgMod  CBX109T                         +
                   **               
              DbgView( *LIST )
                   **
                   **    
              CrtPgm     CBX109T                         +
                   **               
              ModuleCBX109T )               +
                   **               
              BndSrvPgmCBX109S )            +
                   **               
              ActGrpQILE )
                   **
                   **
                   **-- 
              Header specifications:  --------------------------------------------**
                   
              H Option( *SrcStmt )
                   **-- Global 
              definitions:  -----------------------------------------------**
                   
              D FldVal          s           1024a   Varying
                   D DspVal          s             42a
                   
              **
                   
              D SngRqs          c                   0
                   D InzRqs          c                   1
                   D RunRqs          c                   2
                   D TrmRqs          c                   3
                   
              **-- Get field value:  --------------------------------------------------**
                   
              D GetFldVal       Pr          1024a   Varying
                   D  PxRqsTyp                     10i 0 
              Const
                   
              D  PxFilNam                     10a   Const           Options( *NoPass )
                   
              D  PxFldNam                     10a   Const           Options( *NoPass )
                   
              D  PxKey                       256a   Const  Varying  Options( *NoPass )
                   **
                   **-- 
              Mainline:  ---------------------------------------------------------**
                   **
                   
              C                   Eval      FldVal     =  GetFldValSngRqs
                   C                                                    
              'QATOCHOST'
                   
              C                                                    'HOSTNME1'
                   
              C                                                    '127.0.0.1'
                   
              C                                                    )
                   **
                   
              C                   Eval      DspVal     =  FldVal
                   C     
              'HOSTNME1 ='  Dsply                   DspVal
                   
              **
                   
              C                   Eval      FldVal     =  GetFldValInzRqs
                   C                                                    
              'QATOCHOST'
                   
              C                                                    )
                   **
                   
              C                   Eval      FldVal     =  GetFldValRunRqs
                   C                                                    
              'QATOCHOST'
                   
              C                                                    'HOSTNME1'
                   
              C                                                    '127.0.0.1'
                   
              C                                                    )
                   **
                   
              C                   Eval      DspVal     =  FldVal
                   C     
              'HOSTNME1 ='  Dsply                   DspVal
                   
              **
                   
              C                   Eval      FldVal  =  GetFldValRunRqs
                   C                                                 
              'QATOCHOST'
                   
              C                                                 'IPINTGER'
                   
              C                                                 '127.0.0.1'
                   
              C                                                 )
                   **
                   
              C                   Eval      DspVal     =  FldVal
                   C     
              'IPINTGER ='  Dsply                   DspVal
                   
              **
                   
              C                   Eval      FldVal  =  GetFldValRunRqs
                   C                                                 
              'QATOCHOST'
                   
              C                                                 'TXTDESC'
                   
              C                                                 '127.0.0.1'
                   
              C                                                 )
                   **
                   
              C                   Eval      DspVal     =  FldVal
                   C     
              'TXTDESC  ='  Dsply                   DspVal
                   
              **
                   
              C                   Eval      FldVal  =  GetFldValTrmRqs )
                   **
                   
              C                   Return
                   **

              Thanks to Carsten Flensburg 
              This is cool also

              PHP Code:
                    //
                    //  Program Info
                    //

                   
              H BNDDIR('QC2LE'DFTACTGRP(*NOACTGRP('QILE')

                   
              D gethostbyname   pr              *   ExtProc('gethostbyname')
                   
              D   host_name                     *   value

                   D inet_ntoa       pr              
              *   ExtProc('inet_ntoa')
                   
              D   addr                        10u 0 value

                    
              host
                   D host_ptr        s               
              *   Inz(*null)
                   
              D host_ds         ds                  Align Qualified Based(host_ptr)
                   
              D   name_p                        *
                   
              D   aliases_pp                    *
                   
              D   addr_type                   10i 0
                   D   addr_len                    10i 0
                   D   addr_list_pp                  
              *
                   
              D addr_list_p     s               *   Based(host_ds.addr_list_pp)
                   
              D addr_arr        s             10u 0 Dim(1Based(addr_list_p)

                   
              D inetaddr        s             10u 0 Inz(0)
                   
              D c_host          s            256a

                   D c_ipaddr_p      s               
              *
                   
              D c_ipaddr        s             17a   based(c_ipaddr_p)
                   
              D ipaddr          s             16a   varying

                    
              /free

                     ipaddr
              ='';
                     %
              str(%addr(c_host) : %size(c_host)) = 'systemname.domain.com';
                     
              host_ptr gethostbyname(%addr(c_host));
                     if 
              host_ptr <> *null and host_ds.name_p <> *null;
                       
              inetaddr addr_arr(1);
                       
              c_ipaddr_p inet_ntoa(inetaddr);
                       
              ipaddr = %str(c_ipaddr_p);
                     endif;

                     *
              INLR = *on;
                     return;



                    /
              End-Free 
              Last edited by jamief; January 20, 2010, 04:33 PM. Reason: more examples
              All my answers were extracted from the "Big Dummy's Guide to the As400"
              and I take no responsibility for any of them.

              www.code400.com

              Comment


              • #8
                Re: System IP address

                A colleague just suggested checking the libl for specific libs that will only be in each specific environments.
                I think this may work.
                I appreciate your time and help anyway.
                Everyday's a school day, what grade are you in?

                Comment


                • #9
                  Re: System IP address

                  ummmm... Jamie, we've had this discussion before, but I can't find the thread.

                  In Jamies' first post (i.e. post #2), that will return requesting device IP address.
                  To get the host system IP address, replace
                  PHP Code:
                  C                  Eval     Net_Address= %Subst(rcvar:877:16)*** 
                  with
                  PHP Code:
                  C                Eval     Net_Address = %Subst(Rcvar:958:15
                  ***btw... to get the device IP that line should read
                  PHP Code:
                  Eval      Net_Address = %Subst(Rcvar:878:15
                  Incidently, the layout can be copied from
                  Code:
                        // QDCD060000 defines the fixed portion of the DEVD0600 format.  
                       D/COPY QSYSINC/QRPGLESRC,QDCRDEVD
                  So then all you need for the code is
                  Code:
                   GetIPAddr(QDCD060000: 972: 'DEVD0600': DevName: stdError);        
                  if stdError.QUSEC.QUSBAVL > 0;                                    
                    if stdError.QUSEC.QUSEI = 'CPF2702';                            
                      // unknown device                                             
                      eval RtnIndPr = 'N1';                                         
                    else;                                                           
                      // other errors                                               
                      eval RtnIndPr = 'N2';                                         
                    endif;                                                          
                  else;                                                             
                      eval RtnIndPr = 'OK';                                         
                    select;                                                         
                      // IP device address                                          
                      when QDCNP = PROTO_IP;                                        
                        IPAddrDev = QDCIPADF;                                       
                        IPAddr400 = QDCSNIPA;  
                      // SNA device address  
                      // --- not catered for but fill anyway as we might 
                      // --- need it later                                                                  
                      when QDCNP = PROTO_IPX;                                       
                        IPAddrDev = QDCIPADF;                                       
                        IPAddr400 = QDCSNIPA;                                       
                      other;                                      
                        eval RtnIndPr = 'N3';                                                                                               
                    endsl;                                                                
                  endif;                                                                  
                   
                  *inlr = *ON;
                  Last edited by kitvb1; January 21, 2010, 09:07 AM. Reason: cleaned up post (kit please check i didnt fat finger anything)
                  Regards

                  Kit
                  http://www.ecofitonline.com
                  DeskfIT - ChangefIT - XrefIT
                  ___________________________________
                  There are only 3 kinds of people -
                  Those that can count and those that can't.

                  Comment


                  • #10
                    Re: System IP address

                    Kit you calling me a loser!
                    All my answers were extracted from the "Big Dummy's Guide to the As400"
                    and I take no responsibility for any of them.

                    www.code400.com

                    Comment


                    • #11
                      Re: System IP address

                      mmmm... first the eyesight goes at 40, now the memory is also going

                      .... and the cherry on top...
                      I noticed from this year that when I have a web-form to fill in that requires my year of birth.... I have to scroll an extra $%&*#&%$ page to find mine

                      Hold on tight folks, it's all downhill from here.


                      p.s. Yes - the % is missing from the %subst statements
                      p.p.s. The VB4.0.1 is now out - with +- 300 fixes.
                      p.p.s. The VB4.0.2 should be released next week - with another +-200 fixes
                      Last edited by kitvb1; January 21, 2010, 09:10 AM. Reason: added p.s.
                      Regards

                      Kit
                      http://www.ecofitonline.com
                      DeskfIT - ChangefIT - XrefIT
                      ___________________________________
                      There are only 3 kinds of people -
                      Those that can count and those that can't.

                      Comment


                      • #12
                        Re: System IP address

                        you can also visit this link for program to retrieve the system IP.

                        Comment


                        • #13
                          Re: System IP address

                          Or in CL-program:

                          DCL VAR(&RECEIVER) TYPE(*CHAR) LEN(1000)
                          DCL VAR(&RCVLEN) TYPE(*CHAR) LEN(4)
                          DCL VAR(&DEVICE) TYPE(*CHAR) LEN(10)
                          DCL VAR(&SERVER_IP) TYPE(*CHAR) LEN(15)
                          :
                          CHGVAR VAR(%BIN(&RCVLEN)) VALUE(1000)
                          RTVJOBA JOB(&DEVICE)
                          CALL PGM(QDCRDEVD) PARM(&RECEIVER &RCVLEN 'DEVD0600' &DEVICE X'00000000')
                          CHGVAR VAR(&SERVER_IP) VALUE(%SST(&RECEIVER 958 15))
                          :

                          Comment

                          Working...
                          X