tcpdump mailing list archives

Using TCPDUMP from Java


From: "Jordan Rivington" <jordan.rivington () sympatico ca>
Date: Fri, 4 Apr 2003 09:30:46 -0500

I wish to use tcpdump from Java to arvhice raw data. I do so each hour
by running a tcpdump process and killing it at the end of the hour. The
only problem is that killing the process doesn't allow tcpdump to finish
closing th efile properly so it cannot be read. Any suggestions?

Here is my code

import java.io.*;
import java.util.*;

public class systemTcpdumpArchive
{
        public static void main(String[] args) throws IOException
        {
                Process process;
                Calendar rightNow = Calendar.getInstance();
                int hour24 = rightNow.get(Calendar.HOUR_OF_DAY);
                int year=0, month=0, day=0, hour=0;
                String sYear="", sMonth="", sDay="", sHour="";
                String filename="";

                int flag=0;
                while( true )
                {
                        //create new filename
                        year = rightNow.get(Calendar.YEAR);
                        month = rightNow.get(Calendar.MONTH) + 1;
                        day = rightNow.get(Calendar.DATE);
                        hour = rightNow.get(Calendar.HOUR_OF_DAY);

                        sYear = String.valueOf( year );
                        sMonth = String.valueOf( month ).replaceAll("0",
"");
                        sDay = String.valueOf( day ).replaceAll("0",
"");
                        sHour = String.valueOf( hour ).replaceAll("0",
"");

                        filename = sHour + sDay + sMonth + sYear;
                        System.out.println( "New filename: " + filename
+ "\n" );

                        process =  Runtime.getRuntime().exec( "tcpdump
-w " + filename );
                        flag = 0;

                        while( hour24 ==
rightNow.get(Calendar.HOUR_OF_DAY) && flag != 1)
                        {
                                        rightNow =
Calendar.getInstance();
                                        if( hour24 !=
rightNow.get(Calendar.HOUR_OF_DAY) )
                                        {
                                                hour24 =
rightNow.get(Calendar.HOUR_OF_DAY);
                                                flag = 1;
                                        }
                        }

                        process.destroy();
                }
        }
}

Sincerely,

Jordan Rivington

Good programming is 99% sweat and 1% coffee 


-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe


Current thread: