Today, I was preparing another program for automation. I need a function to retrieve an IP address of a remote system from the DNS having the system hostname. In the interactive session, you’d simple use ping or nslookup commands to resolve the hostname. But none of these commands can store the result into a variable. I did a short research, and there is very cool command Start DIG Query (DIG). This command can be used in a program, and it’s very easy get an IP address. Here is the example of a simple CL:
DIG HOSTNAME(‘hostname1’) +
DMNSCHLIST(‘domain.com’) +
IPVSN(*IPV4ONLY) PROTOCOL(*TCP) +
SHORT(*YES) PRTCLASS(*NO) PRTTTL(*NO) +
PRTALL(*NO) CMD(*NO) COMMENTS(*NO) +
STATS(*NO) QUESTION(*NO) ANSWER(*YES) +
AUTHORITY(*NO) ADDITIONAL(*NO) +
TOSTMF(‘/tmp/ipaddress.txt’)
CRTPF FILE(QTEMP/IPADD) RCDLEN(15)
QSYS/CPYFRMSTMF FROMSTMF(‘/tmp/ipaddress.txt’) +
TOMBR(‘/QSYS.LIB/QTEMP.LIB/ipadd.FILE/ipadd+
.MBR’) MBROPT(*REPLACE)
RMVLNK OBJLNK(‘/tmp/ipaddress.txt’)
Coming in 6 years later to say thank you, this is exactly what I was looking for 🙂