Telnet JAVA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • svjames
    New Member
    • Aug 2007
    • 4

    #1

    Telnet JAVA

    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)
    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());
    		}
    	}
    }
  • prometheuzz
    Recognized Expert New Member
    • Apr 2007
    • 197

    #2
    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:
    This beginner Java tutorial describes getting started with Java and setting up your Netbeans IDE


    Good luck.

    Comment

    • svjames
      New Member
      • Aug 2007
      • 4

      #3
      Originally posted by prometheuzz
      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:
      This beginner Java tutorial describes getting started with Java and setting up your Netbeans IDE


      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.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by svjames
        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.

        Comment

        Working...