By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

Telnet JAVA

P: 4
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)
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.net.*;
  3.  
  4. public class TelnetClient {
  5.  
  6.     /**
  7.      * @param args - host, port, username, password
  8.      */
  9.     public static void main(String[] args) 
  10.     {
  11.         //System.out.println("Starting");
  12.         //System.out.println(args[0] + " " + args[1] + " " + args[2] + " " + args[3]);
  13.         new TelnetClient(args[0], args[1], args[2], args[3]);
  14.     }
  15.  
  16.     public TelnetClient(String host, String port, String username, String password)
  17.     {
  18.         //System.out.println(host + " " +port + " " + username + " " + password);
  19.         try
  20.         {
  21.             int intPort = Integer.parseInt(port);
  22.             Socket telnet = new Socket(host, intPort);
  23.  
  24.             //System.out.println(intPort + " " + " " + telnet.getRemoteSocketAddress() + " " + telnet.isConnected());
  25.  
  26.             PrintWriter telnetOut = new PrintWriter(telnet.getOutputStream());
  27.             telnetOut.println(username);
  28.             telnetOut.println(password);
  29.             String exit = "quit";
  30.             telnetOut.println(exit);
  31.             telnetOut.flush();
  32.  
  33.             InputStream telnetIn = telnet.getInputStream();
  34.  
  35.             telnetOut.close();
  36.             telnetIn.close();
  37.             telnet.close();
  38.             //System.out.println(intPort + " " + " " + telnet.getRemoteSocketAddress() + " " + telnet.isConnected());
  39.         }catch(Exception e)
  40.         {
  41.             System.out.println(e.getMessage());
  42.         }
  43.     }
  44. }
  45.  
Aug 21 '07 #1
Share this Question
Share on Google+
3 Replies


prometheuzz
Expert 100+
P: 197
I must say, this is not the best way to learn Java. Perhaps you should ask this friend who supplied you the code how you should be able to compile and run it.
Or learn how to do this yourself:
http://java.sun.com/docs/books/tutor...ted/index.html

Good luck.
Aug 21 '07 #2

P: 4
I must say, this is not the best way to learn Java. Perhaps you should ask this friend who supplied you the code how you should be able to compile and run it.
Or learn how to do this yourself:
http://java.sun.com/docs/books/tutor...ted/index.html

Good luck.
I am very aware that this is not a prefered circumstance, thats why im asking for help. I just need this code to be executable from a web page. My friend has moved away... and i mean antarctica away... so if you could help me compile and rrun it, that would be good.
Aug 21 '07 #3

10K+
P: 13,264
I am very aware that this is not a prefered circumstance, thats why im asking for help. I just need this code to be executable from a web page. My friend has moved away... and i mean antarctica away... so if you could help me compile and rrun it, that would be good.
If you have the class files and the jar files, you don't need to compile it again. To run it from a browser, it has to be an applet. Now we're not going to make the applet for you. We just point you in the right direction. You have to appreciate that you need to put more work into it than you're asking us to put into it.
Aug 22 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.