Hey guys, im working on a project that requires a telnet connection to be made from a web page to a router, auto login then quit/drop whatever, its just gotta run one and in the background. my friend wrote me this code because i know nothing about java but i cant even begin to imagine how to make this thing run.
Ive tried useing html tags like inserting a java applet but this seems not to work.
I know it would be much more respectable to sit down and learn java, but i am really baffled at what i have read and dont really have the time, i just need this code to be executable from a web page,
Can someone please direct me to a solution :(
This is what i have,
thisfile.class
thisfile.jar
thisfile.java <---(this is the text in this file)
Ive tried useing html tags like inserting a java applet but this seems not to work.
I know it would be much more respectable to sit down and learn java, but i am really baffled at what i have read and dont really have the time, i just need this code to be executable from a web page,
Can someone please direct me to a solution :(
This is what i have,
thisfile.class
thisfile.jar
thisfile.java <---(this is the text in this file)
Code:
import java.io.*;
import java.net.*;
public class TelnetClient {
/**
* @param args - host, port, username, password
*/
public static void main(String[] args)
{
//System.out.println("Starting");
//System.out.println(args[0] + " " + args[1] + " " + args[2] + " " + args[3]);
new TelnetClient(args[0], args[1], args[2], args[3]);
}
public TelnetClient(String host, String port, String username, String password)
{
//System.out.println(host + " " +port + " " + username + " " + password);
try
{
int intPort = Integer.parseInt(port);
Socket telnet = new Socket(host, intPort);
//System.out.println(intPort + " " + " " + telnet.getRemoteSocketAddress() + " " + telnet.isConnected());
PrintWriter telnetOut = new PrintWriter(telnet.getOutputStream());
telnetOut.println(username);
telnetOut.println(password);
String exit = "quit";
telnetOut.println(exit);
telnetOut.flush();
InputStream telnetIn = telnet.getInputStream();
telnetOut.close();
telnetIn.close();
telnet.close();
//System.out.println(intPort + " " + " " + telnet.getRemoteSocketAddress() + " " + telnet.isConnected());
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Comment