ACN Packet analysis

import java.io.*;

class Main
{
static int nt=0;
static int nu=0;
public static void main(String args[]) throws Exception
{
FileReader fr=new FileReader(“item1.txt”);
BufferedReader br=new BufferedReader(fr);
String s,s1;
char c;
int i,j,k,ct,cu;

while((s=br.readLine())!=null)
{
i=s.length();
for(j=0;j<i;j++)
{
c=s.charAt(j);
if(c==’,')
{
check(s,j+2);
break;
}
}
}
System.out.println(“No of TCP Connection: “+nt);
System.out.println(“No of UDP Connection: “+nu);
fr.close();
}
public static void check(String s,int j)
{
String s1=s.substring(j,j+3);
String t=”TCP”;
if(s1.equals(t))
{
nt++;
}
else
{
nu++;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.util.*;

class Main
{
static int nt=0;
static int nu=0;
static int pckt=0;
static int pcku=0;
static int szt=0;
static int szu=0;

public static void main(String args[]) throws Exception
{
FileReader fr=new FileReader(“item.txt”);
BufferedReader br=new BufferedReader(fr);
String s,s1;

char c;
int i,j,k,ct,cu;

while((s=br.readLine())!=null)
{

i=s.length();
for(j=0;j<i;j++)
{
c=s.charAt(j);
if(c==’,')
{
check(s,j+1);
break;
}
}
}
System.out.println(“No of TCP Connection: “+nt);
System.out.println(“No of TCP packets: “+pckt);
System.out.println(“Total size of TCP packets received: “+szt);

System.out.println(“********************************************”);
System.out.println(“No of UDP Connection: “+nu);
System.out.println(“No of UDP packets: “+pcku);
System.out.println(“Total size of UDP packets received: “+szu);
fr.close();
}
public static void check(String s,int j)
{
String s1=s.substring(j,j+3);
int m=1;
String t=”TCP”;
if(s1.equals(t))
{
nt++;
cal(s,m);
}
else
{
m=0;
cal(s,m);
nu++;
}
}
public static void cal(String s,int m)
{
StringTokenizer st=new StringTokenizer(s,”,”);
int size=9;
while(size>0)
{
size–;
String t=st.nextToken();
}
String t1=st.nextToken();
String t3=st.nextToken();
int n=Integer.parseInt(t1);
int si=Integer.parseInt(t3);
if(m==1)
{
szt+=si;
pckt+=n;
}
else
{
szu+=si;
pcku+=n;
}
}
}

/*
Output:

C:\Program Files\Java\jdk1.5.0\bin>cmd
Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Program Files\Java\jdk1.5.0\bin>javac Main.java

C:\Program Files\Java\jdk1.5.0\bin>java Main
No of TCP Connection: 49
No of TCP packets: 91523
Total size of TCP packets received: 19136683
********************************************
No of UDP Connection: 33
No of UDP packets: 33
Total size of UDP packets received: 7073

C:\Program Files\Java\jdk1.5.0\bin>
*/

Advertisement

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.