Title: Remote Command Execution
Aim: To write a program in java for Remote Command Execution. ALGORITHM: Step 1: Start the program Step 2: Create two objects for string class. Step 3: Inside create new Socket([Link](), portno()); Step 4: Using object for buffered reader class gets the client date. Step 5: Using object the printer writer class, prints the client date. Step 6: While the user does not enter bye catch the exception. Step 7: On server side, create an object for the server socket class. Step 7: Establish the connection using accept() method of the socket class. Step 8: Get the client input using buffered reader class object. Step 9: Using conditional loop print system data, time etc based on the user request and else print the user is invalid. Step 10: Run the server and client invoke server method on client side. Step 11: Print out with the necessary details.
REMOTESERVER: import [Link].*; import [Link].*; import [Link].*; class remoteserver { public static void main(String args[])throws Exception { String com=new String(); ServerSocket ss=new ServerSocket(100); Socket s=[Link](); BufferedReader nin=new BufferedReader(new InputStreamReader([Link]())); PrintWriter nout=new PrintWriter([Link](),true); do { com=[Link](); if([Link]("date")) { Calendar c=[Link](); [Link]([Link](Calendar.DAY_OF_MONTH)+","+([Link]([Link]) +","+([Link]([Link])+1)+","+[Link]([Link]))); [Link]("Date is [Link] terminated with client"); } else { if([Link]("time")) { Calendar c=new GregorianCalendar(); [Link](new Date()); [Link]([Link]([Link])+","+([Link]([Link]) +1)+","+[Link]([Link])); [Link]("Time is [Link] terminated with client"); } else { [Link]("your request is invalid"); [Link]("Proper response is sent to your client"); } } } while(); [Link]("connection terminated with client");
} } REMOTECLIENT2: import [Link].*; import [Link].*; class remoteclient2 { public static void main(String args[])throws IOException { String rec=new String(); String res=new String(); try { Socket s=new Socket([Link](),100); BufferedReader cin=new BufferedReader(new InputStreamReader([Link])); BufferedReader sin=new BufferedReader(new InputStreamReader([Link]())); PrintWriter nout=new PrintWriter([Link](),true); do { rec=[Link](); [Link](rec); res=[Link](); [Link](res); } while([Link]("bye")); } catch(Exception e) { [Link]("error:"+e); } } }
OUTPUT:
RESULT: Thus, the Remote Command Execution has been implemented successfully.