1

I'm tried to get AS400 TCP Connection Status. but i'm failed :( can anyone help me to do this. i'm new to JT400 java development. please help me friends.

  1. i want to get IP address of a job
  2. i want to get TCP Connection Status using that (1) IP address.

Please help me Thank you!

Edit :

i got this class

com.ibm.as400.util.commtrace.TCPHeader

It's return this informations

getACKFlag()
getAckNum()
getCheckSum()
getCWRFlag()
getDataOffset()
getDstPort() ..etc

now i want to get this informations. its mean, how to get TCP status using this class.

Please help me

Thank You

Dzshean
  • 314
  • 6
  • 23

2 Answers2

3

To get the IP address of a job:

System.out.println("IP address " + job.getValue(job.CLIENT_IP_ADDRESS));
Buck Calabro
  • 7,558
  • 22
  • 25
2

The commtrace classes are not real-time. They use a trace file which was created on the IBM i server at some earlier time. In order to create that trace file, see the Javadoc for com.ibm.as400.util.commtrace.CommTrace Basically you will need to run the IBM i commands STRCMNTRC, ENDCMNTRC and DMPCMNTRC. Then use commtrace.CommTrace to create a trace file formatted so that the other commtrace classes can read it.

EDIT: Add code snippet from commtrace.Format Javadoc

import java.util.*;
import com.ibm.as400.access.*;
import com.ibm.as400.util.commtrace.*;

public class TestCommTrace {
    public static void main(String[] args) {

try {
 Format f = new Format("/buck/linetrace");

 FormatProperties fmtprop = new FormatProperties();
 f.setFilterProperties(fmtprop); // Sets the filtering properties for this Format

 f.formatProlog(); // Format the prolog
 Prolog pro = f.getProlog();    
 System.out.println(pro.toString());

 if(!pro.invalidData()) { // This is not a valid trace
         Frame rec; 
         while((rec=f.getNextRecord())!=null) { // Get the records
                System.out.print("Frame " + rec.getRecNum().toString()); // Print out the Frame Number
                System.out.println(" time " + rec.getTime().toString()); // Print out the time
                IPPacket p = rec.getPacket(); // Get this records packet
                Header h = p.getHeader(); // Get the first header
                if(p.getType()==IPPacket.IP4) { // If IP4 IPPacket
                        if(h.getType()==Header.IP4) { // If IP4 Header
                                IP4Header ip4 = (IP4Header) h; // Cast to IP4 so we can access methods
                                System.out.println(h.getName()); // Print the name
                                System.out.println("IP4 src:"+ip4.getSrcAddr() + " dst:" + ip4.getDstAddr());
                                System.out.println(ip4.printHexHeader()); // Print the header as hex 
                                // Print a string representation of the header.
                                System.out.println(ip4.toString()); // hex string
                                //System.out.println(ip4.toString(fmtprop)); // very detailed
                                while((h=h.getNextHeader())!=null) { // Get the rest of the headers
                                        if(h.getType()==Header.TCP) { // If its a TCP header
                                                TCPHeader tcp = (TCPHeader) h; // Cast so we can access methods
                                                System.out.println("TCP src:" + tcp.getSrcPort() + " dst:" + tcp.getDstPort() + " checksum:" + tcp.getCheckSum()); 
                                                System.out.println(tcp.toString());  // hex string
                                                //System.out.println(tcp.toString(fmtprop));  // very detailed

                                        } else if(h.getType()==Header.UDP) { // If its a UDP header
                                                UDPHeader udp = (UDPHeader) h; // Cast so we can access methods
                                                System.out.println("UDP src:" + udp.getSrcPort() + " dst:" + udp.getDstPort()); 
                                                System.out.println(udp.toString());
                                        }
                                }
                        }
                }
         } 

 f.close();
 }      
    } catch (Exception e) {
      e.printStackTrace();
    }
}

}

EDIT: Some more detailed information

1) On the IBM system, someone with special permission must run STRCMNTRC and collect communications trace information. This trace file contains all of the TCP packets that flowed between the IBM system and the outside world. For example, if the trace runs for an hour, it will collect every packet the system sent and received during that hour. The trace data is stored in a format that is special and can not be directly read.

2) To make the trace data readable, use the DMPCMNTRC command. This will create a flat text stream file out of the trace data. This data needs to get to your PC so that the com.ibm.as400.util.commtrace classes can work on it.

3) On your PC, run com.ibm.as400.util.commtrace.CommTrace. This will create a file in a simple text form that com.ibm.as400.util.commtrace can process. I put mine in /buck/linetrace. It is important to understand that there are hundreds or thousands of packets in this log, and every one of them has the information you ask about in the question. There is not one single ACK flag, there are many hundreds of them. In order to understand what is happening, your program will need to read a packet, get the header, then the status, get the data and then read the next packet, and the next and the next, all the way through them all.

4) In order to filter by IP address, you can either use setFilterProperties() or have your code check the IP addresses in each packet header and only process the headers you want to.

It is important to understand that the 'status' you are looking for is not a property of an IP address, it is a property of a TCP packet. There is no way to ask the system for the ACK flag of an IP address because there is no such property to be returned. The only way to get these things is to record them at the instant the packet is read or written by the system.

I would be very surprised if you really need these flags; almost no one does. Usually, 'connection status' means a way to determine if the machine is running or not. ping is the typical way to answer that question, but not all machines will answer a ping. For those machines, the best way is to try to connect to the machine and port you want to test.

Buck Calabro
  • 7,558
  • 22
  • 25
  • @ Buck Calabro - Friend, something i can't undestand. can you give me some example ? Thank you! – Dzshean May 07 '13 at 03:01
  • I wish I had the time to write the code for you but my job keeps me very busy! You will not be able to use the commtrace.TCPHeader class to get status about a job that is running right now. That class is meant to help you analyse the contents of a communications trace. – Buck Calabro May 07 '13 at 14:20
  • if you can write sample, it's very helpful to me friend. i am tried to do this. but something missing. i can't understand it. again and again i will try. i'm beginner to this JT400. thnks :) – Dzshean May 07 '13 at 14:41
  • Please edit your question. Post each step you took. Post the code you are trying. Post the exact error you are getting. It's OK to be a beginner. It is easier to correct code than to teach it! – Buck Calabro May 07 '13 at 15:12
  • @ buck ,Thanks my friend. Thank you so much. buck i have 1 problem. where the place to insert "HOSTNAME","USER","PASS" ?? and what is this "/buck/linetrace" ??? sorry for it buck. please tell me it friend. Thank you Friend – Dzshean May 08 '13 at 21:32
  • /buck/linetrace comes from following the instructions in the link to com.ibm.as400.util.commtrace.CommTrace which is in the answer. "HOSTNAME","USER","PASS" are not used for this. – Buck Calabro May 09 '13 at 01:40
  • Hello Buck, friend then how to i'm get TCP details of my own server without server loging details("HOSTNAME","USER","PASS"). i mean as400 system. to get job details and user details, i used "HOSTNAME","USER","PASS" but How to get TCP without connection. i'm how to find my own "/buck/linetrace" link ?? thank you friend – Dzshean May 13 '13 at 15:09
  • and how to search this details using ip address. please help me buck. you are the only friend to help me. sorry for my bad english :( – Dzshean May 13 '13 at 15:11
  • buck , "/buck/linetrace" is local trace path or server trace path ? – Dzshean Aug 01 '13 at 12:30
  • 1
    STRCMNTRC, ENDCMNTRC and DMPCMNTRC are all run on the IBM i. The IBM system administrator must give you authority to use these commands. The '/buck/linetrace' file is created on my PC by running com.ibm.as400.util.commtrace.CommTrace – Buck Calabro Aug 01 '13 at 13:33
  • buck , if i have administrator authority, then how to run that commands (STRCMNTRC, ENDCMNTRC and DMPCMNTRC) for create , make readable ( create flat text stream file) and get it to local PC ? Thank you very much for your advice and replies :) – Dzshean Aug 01 '13 at 13:46
  • Easiest way to run commands is to open a 5250 emulator, connect to IBM i, sign on and type the command name on the command line, then press F4 for more help. You should really ask your system administrator to show you how this works. – Buck Calabro Aug 01 '13 at 13:58
  • buck , can i run that commands using my java application ? (create trace file , convert it to flat stream text file and save it to local PC) is there have any way to do it in java Application ? – Dzshean Aug 01 '13 at 19:00
  • And what is the way ? i mean how to call that command. and create trace file and save it to my PC ? – Dzshean Aug 01 '13 at 19:01
  • JT400's CommandCall can do that. http://javadoc.midrange.com/jtopen/com/ibm/as400/access/CommandCall.html – Buck Calabro Aug 01 '13 at 19:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34649/discussion-between-lakmal-udayanga-and-buck-calabro) – Dzshean Aug 01 '13 at 19:18
  • Using that class i can run commands. but how to change and setting trace file path ? save it to computer ? – Dzshean Aug 01 '13 at 19:39
  • Cmmand = STRCMNTRC AS400 system = new AS400("SYSTEM"); CommandCall command = new CommandCall(system); if (command.run("STRCMNTRC") != true) { System.out.println("Command failed!"); } system.disconnectService(AS400.COMMAND); – Dzshean Aug 01 '13 at 19:41
  • Use java com.ibm.as400.commtrace.Commtrace to process the trace file created by DMPCMNTRC. – Buck Calabro Aug 01 '13 at 19:43
  • buck, if you have some sample code for command call and create trace file , convert it to flat stream text file and save it to local PC. how to use java com.ibm.as400.commtrace.Commtrace ? please give me. it's very helpful to me. i want to learn it. thank you – Dzshean Aug 01 '13 at 20:11
  • 1
    You posted a good example of CommandCall. I do not have an example for Commtrace. I suggest you try it. If you have problems, create another question and post the code that you tried. – Buck Calabro Aug 01 '13 at 20:24
  • Thank you buck. your advice is very helpful for my work. Thank you very very much. I'll try again to find Commtrace. hope your help future :D – Dzshean Aug 01 '13 at 20:40
  • buck, friend if you can, please check this [link](https://www.java2s.com/Open-Source/Java/Net/jtopen-7.0/com/ibm/as400/util/commtrace/CommTrace.java.htm) and tell me is it correct. it's a big code. i can't understand it correctly – Dzshean Aug 01 '13 at 20:46
  • The link you posted is the source for Commtrace. You don't want that unless you plan on changing it. To use that utility, see the Javadoc at http://javadoc.midrange.com/jtopen/com/ibm/as400/util/commtrace/CommTrace.html – Buck Calabro Aug 01 '13 at 20:58
  • hello buck, im Run this command on STRCMNTRC CFGOBJ(LKTEST2) CFGTYPE(*LIN) MAXSTG(128K) – Dzshean Aug 02 '13 at 18:05
  • hello buck, i was Run this command on STRCMNTRC CFGOBJ(LKTEST2) CFGTYPE(*LIN) MAXSTG(128K). im connected to 5250 emulator and run that commands. but no file created :( if u know to do this, please tell me can u tell me how to do it ? – Dzshean Aug 02 '13 at 18:20
  • Lakmal, read the answer again. Step 1 is STRCMNTRC, step 2 is DMPCMNTRC, step 3 is Commtrace. You need to do all the steps to get a file. – Buck Calabro Aug 02 '13 at 19:29
  • buck , please check this Images. it's have my problem 1. im filled detail About communications trace file. check this [link](http://img.krkrkrkr.kr/1308/03/0439X.jpg) for Screenshot 2. and i press enter. after it shows this Error " Line description TESTFILE not found." this is error message [link](http://img.krkrkrkr.kr/1308/03/0441F.jpg) 3. Please Check this [link](http://img.krkrkrkr.kr/1308/03/0450Y.jpg) I DONT KNOW HOW TO FILL THIS DETAILS CORRECTLY PLEASE HELP MY FRIEND. THANK YOU – Dzshean Aug 02 '13 at 19:54
  • buck, did you see that error ? "Command failed! Line description MYTEST not found." Can help me please ? – Dzshean Aug 02 '13 at 20:10
  • The things you are asking about are very specific to your machine. You need to get those details from your system administrator. – Buck Calabro Aug 02 '13 at 23:11
  • buck, can i get TCP connection status without using IFS file. i want only IPV4 Details. i want to get this window details [Screenshot](http://i.stack.imgur.com/Z7XNm.jpg) – Dzshean Aug 05 '13 at 14:41
  • Yes. Use the QtocLstNetCnn API. I do not have a Java example. If I were doing it I would write an SQL stored procedure in RPG that would return a result set which I could then supply to a Java program. – Buck Calabro Aug 05 '13 at 15:11
  • Work with IPv4 Connection Status Type options, press Enter. 3=Enable debug 4=End 5=Display details 6=Disable debug 8=Display jobs ---||||- can i use QtocLstNetCnn API in java ? i want to get All IPV4 Ips and Ip's Details (Option 5) and Display job of that ip (option 8) Can i get this details using this class on java ? without creating IFS file ? – Dzshean Aug 05 '13 at 17:38
  • I think you can use QtocLstNetCnn in Java. No IFS files needed, but you will need to create a user space to hold the list. http://javadoc.midrange.com/jtopen/com/ibm/as400/access/UserSpace.html I do not have any Java examples of this. Here is a Java example of a different API I found on the web: http://www.java2s.com/Open-Source/Java/Net/jtopen-7.0/com/ibm/as400/access/MemberList.java.htm Good luck! – Buck Calabro Aug 05 '13 at 17:52
  • thank you so much buck. your help very important for me. can u check this [link](http://www.mcpressonline.com/networking/general/retrieve-tcpip-api-information-using-java-toolbox.html) and tell me can i do my work using this ? thank you so much :D – Dzshean Aug 05 '13 at 20:31
  • That link is not the same API. You can use that for ideas on implementing the APIs you need. – Buck Calabro Aug 05 '13 at 20:45
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34876/discussion-between-lakmal-udayanga-and-buck-calabro) – Dzshean Aug 05 '13 at 21:30
  • thank you buck, my friend, i started new Question. [This is link](http://stackoverflow.com/questions/18068428/how-to-get-ipv4-connection-status-to-java-jt400-application) help me to find sample. thanks a lot :D – Dzshean Aug 05 '13 at 22:11