io.netty.handler.codec.socksx.v5.DefaultSocks5CommandRequest Java Examples

The following examples show how to use io.netty.handler.codec.socksx.v5.DefaultSocks5CommandRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Socks5ProxyHandler.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
private void sendConnectCommand(ChannelHandlerContext ctx) throws Exception {
    InetSocketAddress raddr = destinationAddress();
    Socks5AddressType addrType;
    String rhost;
    if (raddr.isUnresolved()) {
        addrType = Socks5AddressType.DOMAIN;
        rhost = raddr.getHostString();
    } else {
        rhost = raddr.getAddress().getHostAddress();
        if (NetUtil.isValidIpV4Address(rhost)) {
            addrType = Socks5AddressType.IPv4;
        } else if (NetUtil.isValidIpV6Address(rhost)) {
            addrType = Socks5AddressType.IPv6;
        } else {
            throw new ProxyConnectException(
                    exceptionMessage("unknown address type: " + StringUtil.simpleClassName(rhost)));
        }
    }

    ctx.pipeline().replace(decoderName, decoderName, new Socks5CommandResponseDecoder());
    sendToProxyServer(new DefaultSocks5CommandRequest(Socks5CommandType.CONNECT, addrType, rhost, raddr.getPort()));
}
 
Example #2
Source File: ProxyClientIntegrationTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, Socks5Message msg) throws Exception {
    if (msg instanceof DefaultSocks5InitialRequest) {
        ctx.pipeline().addBefore(ctx.name(), Socks5CommandRequestDecoder.class.getName(),
                                 new Socks5CommandRequestDecoder());
        ctx.writeAndFlush(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH));
    } else if (msg instanceof DefaultSocks5CommandRequest) {
        final DefaultSocks5CommandRequest req = (DefaultSocks5CommandRequest) msg;
        ctx.pipeline().remove(Socks5CommandRequestDecoder.class);
        ctx.fireUserEventTriggered(new ProxySuccessEvent(
                new InetSocketAddress(req.dstAddr(), req.dstPort()),
                new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS,
                                                 Socks5AddressType.IPv4)));
    } else {
        throw new IllegalStateException("unexpected msg: " + msg);
    }
}
 
Example #3
Source File: ProxyToServerConnection.java    From PowerTunnel with MIT License 5 votes vote down vote up
@Override
protected Future<?> execute() {
    InetSocketAddress destinationAddress = unresolvedAddressFor(serverHostAndPort);
    DefaultSocks5CommandRequest connectRequest = new DefaultSocks5CommandRequest(
            Socks5CommandType.CONNECT, Socks5AddressType.DOMAIN, destinationAddress.getHostString(), destinationAddress.getPort());

    addFirstOrReplaceHandler(SOCKS_DECODER_NAME, new Socks5CommandResponseDecoder());
    return writeToChannel(connectRequest);
}