现在已经找了个实例,但是只能连接个服务器,我现在想连接成功后执行一系列的常用命令,比如登录用户名后,输入密码,查看信息操作之后再退出。
请大家多多指点!

解决方案 »

  1.   

    我用socket连接,但执行命令不行,不知道还要什么?待会帖个例子,也是找来的!
      

  2.   

    java.net包里应该有足够的API吧,具体的我也没写过
      

  3.   

    import java.net.*;
    import java.io.*;
    public class WebConnect{
    public static void main(String[] args){
    /*try{

    Process process = Runtime.getRuntime().exec ("telnet bbs.njupt.edu.cn 23"+'\n');
    InputStreamReader ir=new InputStreamReader(process.getInputStream());
    LineNumberReader input = new LineNumberReader (ir);
    String line;
    while ((line = input.readLine ()) != null)
    System.out.println(line);
    }
    catch (java.io.IOException e){
    System.err.println ("IOException " + e.getMessage());
    }*/

    try{
    Socket connection=new Socket(args[0],23);
    System.out.println("Connection established:");
    System.out.println("Local Connection Information");
    System.out.println("\t address:" + connection.getLocalAddress());
    System.out.println("\t port:" +connection.getLocalPort());
    System.out.println("Remote connection Information:");
    System.out.println("\t address:" + connection.getInetAddress());
    System.out.println("\t port :"+connection.getPort());
    // Socket user=new Socket(args[1],23);
    // System.out.println("Connection established:");
    // Process process =Runtime.getRuntime().exec("xxwan");
    // System.out.println("longin finished");




    connection.close();
    }catch (UnknownHostException uhe){
    System.err.println("Unknown host:"+args[0]);
    System.out.println('\n'+"不能分析或无效");
    }catch(IOException ioe){
    System.err.println("IOException: "+ ioe);
    System.out.println('\n'+"不能打开");
    }
    }
    }命令提示符下输入: java WebConnect 10.10.136.32
    可以输出
    Connection established:
    Local Connection Information
             address:/10.10.133.134
             port:1477
    Remote connection Information:
             address:/10.10.136.32
             port :23
    但我现在想在连接后,以某个用户名登录,并输入密码,然后再退出,不知道怎么实现?
      

  4.   

    找了一个 commons-net.jar