Topic subject: PC health of remote sever (Mini Project)
Posted: Thu Oct 16, 2008 6:15 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 57 time
* Project Name:
PC health of remote sever * Programmer:Sumit Agarwal * Type:Network * Technology:Java * IDE:Any * Description:I have created a socket4444 on a PC which I treat as a server. Now using my PC I am firing all system and DOS commands on the server and getting response of same on my PC.
Code:
// To be run at server side and will act as a server // MainServer.java
import java.net.*; import java.io.*;
public class MainServer { public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(4445); } catch (IOException e) { System.err.println("Could not listen on port: 4445."); System.exit(1); }
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true); BufferedReader in = new BufferedReader( new InputStreamReader( clientSocket.getInputStream())); String inputLine, outputLine; MainProtocol kkp = new MainProtocol();
// Server side component used to execute commands and returning result // MainProtocol.java
import java.lang.*; import java.io.*; public class MainProtocol { String sa,sb; // String sb,sa;
public String processInput(String args) { try { sb = new String(); sa = new String(); Runtime rt=Runtime.getRuntime(); Process p=rt.exec("cmd /c "+ args); InputStream is = p.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); while ((sb = br.readLine()) != null) { sa += sb ; // sa +=" "; }