【问题标题】:http request over ssh tunnel通过 ssh 隧道的 http 请求
【发布时间】:2014-08-19 11:43:47
【问题描述】:

我有两台服务器。我使用第一个服务器安装的 Tor 应用程序来隐藏我的 IP 地址。以后将被命名为 SSH Tunnel Server。第二台服务器是在 ssh 隧道上发送 http 请求。它将被命名为客户端服务器。 出于上述目的,我编写了下面的代码。但我无法读取 SSH 隧道服务器响应。我在哪里做错了?

            String user = "root";
            String password = "password";
            String host = "198.199."11.111";
            int port=22;

            JSch jsch = new JSch();
            Session session = jsch.getSession(user, host, port);
            session.setPassword(password);
            session.setConfig("StrictHostKeyChecking", "no");



            session.connect();

            Channel channel=session.openChannel("direct-tcpip");
            ((ChannelDirectTCPIP)channel).setHost("whatismyipaddress.com");
            ((ChannelDirectTCPIP)channel).setPort(80);

            String cmd = "GET / HTTP/1.1" ;

            InputStream in = channel.getInputStream();
            OutputStream out = channel.getOutputStream();
            channel.setInputStream(System.in);
            channel.setOutputStream(System.out);
            channel.connect(10000);

            byte[] bytes = cmd.getBytes();          
            InputStream is = new ByteArrayInputStream(cmd.getBytes("UTF-8"));

            int numRead;

            while ( (numRead = is.read(bytes) ) >= 0) {

                  out.write(bytes, 0, numRead);
                  System.out.println(numRead);
            }

            out.flush();

            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                for (String line; (line = reader.readLine()) != null;){
                    System.out.println(line);
                }
            } catch (java.io.IOException exc) {
                System.out.println(exc.toString());
            }
            channel.disconnect();
            session.disconnect();
            System.out.println();

【问题讨论】:

    标签: java ssh jsch ssh-tunnel


    【解决方案1】:

    您没有在 GET 命令之后输出任何行终止符。尝试将 GET 字符串更改为:

    String cmd = "GET / HTTP/1.1\r\n\r\n";
    

    【讨论】:

      猜你喜欢
      • 2013-09-28
      • 2012-03-20
      • 2016-09-09
      • 2014-09-03
      • 2013-05-26
      • 2012-08-15
      • 2018-09-02
      • 2019-01-12
      • 1970-01-01
      相关资源
      最近更新 更多