This procedure was written to retrieve the IP address of a device.  This can be used to identify a specific device.  For example if you have an application that in a manufacturing environment that is assigned to a facility (work station) you can assign a static IP address on the device.  Write that information to a DB2 table, then use this procedure to identify the device with the facility.

Objects:

  • GETIP
    • main processing code
  • GETIP_CP
    • copy book of the “pr”
  • GETIP_TST
    • An example of how to use the procedure

 

GETIP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
H NOMAIN EXPROPTS(*RESDECPOS)
* PROGRAM - GETIP
* PURPOSE - Get IP address
* WRITTEN - 02/14/17
* AUTHOR - Jamie Flanary
// -------------------- Data Structures --------------------
d Apierror ds Qualified
d BytesProvided 10i 0 Inz(%size(Apierror))
d BytesAvailable 10i 0 Inz(0)
d MessageID 7a Inz
d Rsvd 1a Inz
d MessageData 1024a Inz

d MyData ds qualified
d Ip_Address 16a overlay(MyData:878)

d psds sds
d Qualified
d PgmName *Proc
d DeviceID 10A Overlay(PSDS: 244)
d JobUser 10A Overlay(PSDS: 254)

// ------------------ Standalone Variables -----------------
d TheIPAddress s 15 inz
d Net_Address s 20A INZ
d Format s 8A Inz('DEVD0600')
d Rcvar s 5000A Inz
d Varlen s 10i 0 Inz(5000)

// ---------------------- Constants ------------------------
d Q c Const('''')
d standardlen c Const(36)
// ---------------------- Indicators -----------------------
//==============================================================*
// PROTOTYPES *
//--------------------------------------------------------------*

/copy qprcsrc,GETIP_CP

d $getipaddress pr extpgm('QDCRDEVD')
d rcvar 5000
d varlen 10i 0
d format 8
d @job 10
d apierror 256

//==============================================================*
// PROCEDURE INTERFACE *
//--------------------------------------------------------------*
pGetIPAddress B Export
dGetIPAddress PI 16A

/free
// Retrieve IP address of device: must be interactive call to get IP address
$getipaddress( rcvar :
varlen :
format :
psds.DeviceID:
Apierror
);

if ApiError.MessageID = *blanks;
MyData.Ip_Address = %subst(Rcvar:878:15);
endif;

Return MyData.Ip_Address;

/end-free

PGetIPAddress E

GETIP_CP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//***************************************************************
//
// RBS
//
//***************************************************************
// Module Name -- GETIP
// Written By -- JJF Date Written -- 02/14/2017
// Modified By -- X.X.X. Last Revision -- XX/XX/XXXX
//***************************************************************
// List all modifications to this program below in the
// format of initials, date & description of your change.
//
// Initials Date Description
// JJF 02/14/17 Procedures
//
//***************************************************************
// Module Description
//
// Get GUID
//***************************************************************

//==============================================================*
// PROTOTYPES *
//--------------------------------------------------------------*

dGetIPAddress pr 16a ExtProc('GETIP')

GETIP_TST

1
2
3
4
5
6
7
8
9
H DFTACTGRP(*NO) OPTION(*SRCSTMT: *NODEBUGIO) BNDDIR('UTILITIES')

/copy qprcsrc,GETIP_CP

d ReturnIP s 16 Inz

*inlr = *on;

ReturnIP = GetIPAddress();

Using SQL to get IP address:

1
2
3
SELECT trim(substr(LOCAL_HOST_NAME,1,20)) as system_name,
CLIENT_IP_ADDRESS_TYPE, CLIENT_IP_ADDRESS,
CLIENT_PORT_NUMBER, HOST_VERSION FROM QSYS2.TCPIP_INFO

this would return:

SYSTEM_NAME = DTASTORE.???.COM
CLIENT_IP_ADDRESS_TY = IPV4 
CLIENT_IP_ADDRESS = 10.100.1.7
CLIENT_PORT_NUMBER = 61,583
HOST_VERSION = V7R2M0 
Retrieve IP Address

Procedure to retrieve IP address assigned to a specific hardware device.

 

Get IP Address
Tagged on:     

One thought on “Get IP Address

  • March 20, 2020 at 1:54 pm
    Permalink

    Example in SQLRPGLE

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    d SystemName      s             20    inz                                  
    d IpType          s              5    inz                                  
    d IpAddress       s             15    inz                                  
    d PortNumber      s             10i 0 inz                                  
    d OSVersion       s             10    inz                                  
                                                                               
      exec sql set option --Naming = *Sys,commit = *none,                      
                            datfmt = *ISO,srtseq = *langidunq;                
      *inlr = *on;                                                            
                                                                               
      exec sql                                                                
       SELECT trim(substr(LOCAL_HOST_NAME,1,20)) as system_name,              
       CLIENT_IP_ADDRESS_TYPE, CLIENT_IP_ADDRESS,                              
       CLIENT_PORT_NUMBER, HOST_VERSION                                        
       Into :SystemName, :IpType,  :IPaddress, :PortNumber, :OSVersion        
       FROM QSYS2.TCPIP_INFO                                                  
       with NC;
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *