abdulraqeeb33 7 Light Poster

this is the output on server

init:
deps-jar:
compile-single:
run-single:
checking the client of ip 169.254.86.65
checking the client at port 59000
checking the client at hostname RAF
System with169.254.86.65is online
probing the client of ip 169.254.86.65
creating the client of ip 169.254.86.65 whose hostname is RAF at port 59000
Unable to create socket herenull
BUILD SUCCESSFUL (total time: 3 seconds)


output at client


init:
deps-jar:
compile-single:
run-single:
Adaptation client starting at:59000
Adaptation client started at:59000
uNABLE TO create serversocket in adaptclient,Retry restarts apllication
Error Description------->java.net.SocketException: Connection reset by peer: socket write error
BUILD SUCCESSFUL (total time: 2 seconds)



server program


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


package server;


/**
*
* @author 007
*/
import java.io.*;
import java.sql.*;
import java.net.*;
import java.io.InputStream;
import java.lang.Object.*;
import java.net.Socket.*;
import java.lang.String.*;
/**
*
* @author pavithra
*/


public class adaptserver
{



static ResultSet res;
static Connection conn;
static Statement stat;
public static void main(String[] arg) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//DONOT CHANGE  THIS
conn = DriverManager.getConnection("jdbc:odbc:MS Access Database");//msk is the DSN Name
stat = conn.createStatement();


res = stat.executeQuery("select * from clients_online");
String client_ip="null"; //initialize an array of strings to store the ip address
while(res.next())
{
client_ip=res.getString(1);
String client_mac=res.getString(2);
int client_port=res.getInt(6);//adapt port
String hostname=res.getString(7);
hostname=hostname.substring(0, 3);
hostname =hostname.toUpperCase();
System.out.println("checking the client of ip "+client_ip);
System.out.println("checking the client at port "+client_port);
System.out.println("checking the client at hostname "+hostname);
int avail= pinging(client_ip);


if (avail==1)
{
System.out.println("System with"+client_ip+"is online");
int k=probe(hostname,client_ip,client_mac,client_port);
}
else
{
offline(client_ip,client_mac);
}
}//while
}//main
static void offline(String ip,String mac) throws SQLException
{
System.out.println("the client of ip "+ip+" is offline");
try{
stat.execute("delete * from clients_online where ip='"+ip+"' and mac='"+mac+"'"); //update the status..


}
catch(SQLException e)
{
System.out.println("unable to write into database"+e.getMessage());//work here
}


}


static int pinging(String ip) throws Exception
{
String cmd = "ping "+ip;
Runtime runtime = Runtime.getRuntime();
Process p=runtime.exec(cmd);//Running ipconfig -all in cmd prompt
InputStreamReader isr=new InputStreamReader(p.getInputStream());//Readind the STDOUT
BufferedReader brd = new BufferedReader(isr);//Placing read info in buffer
String line=null;
int flag=0;
while(true)
{
line=brd.readLine();
if(line.startsWith("Reply"))
{
flag=1;
break;
}
}
if(flag==1)
return 1;
else
return 0;


}//pinging class



static int probe(String hostname,String ip,String mac,int clientport ) throws Exception
{



//ip=ip.substring(4);
try{
System.out.println("probing the client of ip "+ip);
//InetAddress inetAddress = InetAddress.getByName(ip);
//String hostname = inetAddress.getHostName();//getting the hostname of ip
System.out.println("creating the client of ip "+ip+" whose hostname is "+hostname+" at port "+clientport);
Socket socket = new Socket(hostname, clientport);
InputStream sin = socket.getInputStream();
DataInputStream in = new DataInputStream(sin);
//OutputStream sout = socket.getOutputStream();
//DataOutputStream out = new DataOutputStream(sout);
//String line = null;
//line = "send ip and mac";
//out.writeUTF(line);
//out.flush();
int t=0; String reccli_mac= null;
String reccli_ip=null;


while(t==1)
{
reccli_mac= in.readUTF();
reccli_ip=in.readUTF();
t=0;
}
if(reccli_mac.equals(mac)&& reccli_ip.equals(ip) )
{
try{
stat.execute("update clients_online set status='1' where ip='"+reccli_ip+"' and mac='"+reccli_mac+"'"); //update the status..
}
catch(SQLException e)
{
System.out.println("unable to write into database"+e.getMessage());//work here
}
return 1;
}
else
{
System.out.println("Intruder alert");
stat.execute("delete * from cients_online where IP='"+reccli_ip+"'and mac='"+reccli_mac+"'");
stat.execute("insert into blocked values('"+reccli_ip+"','"+reccli_mac+"')");
//intruder alert..work here
return 0;
}}
catch(Exception e)
{
System.out.println("Unable to create socket here"+e.getMessage());
}
return 0;


}//adpts class
}


client program


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/


package test;


/**
*
* @author 007
*/



import java.io.*;
import java.net.*;
import java.lang.Object.*;
import java.sql.*;
import java.net.ServerSocket.*;
import java.lang.String.*;
import java.util.StringTokenizer;


public class adaptclient {
public static void main(String[] args) throws IOException
{
int port=59000;
ServerSocket srv;
Socket socket;
try{
System.out.println("Adaptation client starting at:"+port);
srv = new ServerSocket(port);
System.out.println("Adaptation client started at:"+port);
socket = srv.accept();
OutputStream sout = socket.getOutputStream();
DataOutputStream out = new DataOutputStream(sout);
String ip=null;
String mac=null;
try
{
Runtime runtime = Runtime.getRuntime();
Process p=runtime.exec("ipconfig -all");//Running ipconfig -all in cmd prompt
InputStreamReader isr=new InputStreamReader(p.getInputStream());//Reading the OUTPUT
BufferedReader brd = new BufferedReader(isr);//Placing read info in buffer
String nexttok="";//Temp buffer to store the tokens
String a="";//To Store the entire Physical Address line
int count=0;
while(true)
{
String requestLine = brd.readLine();
StringTokenizer tokens = new StringTokenizer(requestLine, " ");
if(count==2)//When the second "Wireless" word is encountered in Description row
{
requestLine = brd.readLine();
a=requestLine;//Stores the entire Physical Address line now
break;
}//if
while(tokens.hasMoreTokens())
{
nexttok=tokens.nextToken();
if (nexttok.startsWith("Wireless"))
count++;
}//inner while
}//outer while
mac= a.substring(44,61);//Extracting the Mac address from the Physical Address line


}
catch(Exception e)
{
String a=null;String serv[]=new String [10];
a="Enable wireless connection(IP), adaptation client not working,Retry restarts apllication\nError Description------>"+e.toString();
test.fail.start(a,serv,"adapt");
}


//TO OBTAIN IP
try
{
InetAddress myself = InetAddress.getLocalHost ();


ip=myself.toString();
ip=ip.substring(4);


}
catch(Exception e)
{
String a=null;String serv[]=null;
a="Enable wireless connection(IP), adaptation client not working,Retry restarts apllication\nError Description------->"+e.toString();
test.fail.start(a,serv,"adapt");
}
int t=0;
while(t==0)
{
out.writeUTF(mac);
out.flush();
out.writeUTF(ip);
out.flush();
t=1;
}
}
catch(IOException e)
{
String a=null;String serv[]=null;
a="uNABLE TO create serversocket in adaptclient,Retry restarts apllication\nError Description------->"+e.toString();
System.out.println(a);
//test.fail.start(a,serv,"adapt");


}



}
}

can anyone plz tell me wat is going wrong