Java隧道和tcp代理 [英] Java tunnel and tcp proxy

查看:155
本文介绍了Java隧道和tcp代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过 tcp 代理进行隧道传输.在Java 中,代理类型只有socks、direct 或HTTP.因此,在下面的示例中,正在创建一个套接字,然后从 socketAddress 创建代理对象,并且类型为 socks.
如何指定代理是 TCP?

I need to tunnel through a tcp proxy. Within Java, the proxy types are only socks, direct or HTTP. So in the example below a socket is being created then the proxy object is being created from the socketAddress and the type is socks.
How can I specify the proxy is TCP?

    SocketAddress addr = new InetSocketAddress("socks.example.com", 1080);
    Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
    Socket socket = new Socket(proxy);
    InetSocketAddress dest = new InetSocketAddress("server.example.org", 1234);
    try {
        socket.connect(dest);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return isValidated;

推荐答案

您希望在设置为隧道到目的地的端口上有一个到 Localhost 的直接代理.例如,如果您的隧道设置为从 4000(本地)到 3389(在您真正想要连接的主机上),则目标是 Localhost,1000,代理类型为 Direct.请参阅通过 JSch 的 SSH 隧道

You want a DIRECT proxy to Localhost on the port you set up to tunnel to the destination. For example if your tunnel is set up to go from 4000 (Local) to 3389 (on the host you really want to connect to) the destination is Localhost, 1000, proxy type Direct. See SSH tunneling via JSch

这篇关于Java隧道和tcp代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆