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

[cc lang=”php”]

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

[/cc]

GETIP_CP

[cc lang=”php”]

//***************************************************************
//
// 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’)

[/cc]

GETIP_TST

[cc lang=”php”]

H DFTACTGRP(*NO) OPTION(*SRCSTMT: *NODEBUGIO) BNDDIR(‘UTILITIES’)

/copy qprcsrc,GETIP_CP

d ReturnIP s 16 Inz

*inlr = *on;

ReturnIP = GetIPAddress();

[/cc]

Using SQL to get IP address:

[cc lang=”php”]

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

[/cc]

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
Retrieve IP Address

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

 

Get IP Address
Tagged on: