Search in sources :

Example 6 with Socks5Request

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.

the class Socks5HostResolver method resolve.

@Override
public InetAddress resolve(final String host) throws IOException {
    if (host == null) {
        return InetAddress.getLoopbackAddress();
    }
    Properties properties = this.socks5Client.getProperties();
    AddressType addressType = AddressType.valueForString(host);
    if (!addressType.equals(AddressType.DOMAINNAME) || !properties.getValue(Socks5PropertySpecConstants.SOCKS5_RESOLVE_USE_RESOLVE_COMMAND).booleanValue()) {
        return InetAddress.getByName(host);
    }
    Socket socket = this.socks5Client.newInternalSocket();
    this.socks5Client.configureInternalSocket(socket);
    Socket sock = this.socks5Client.getConnectedInternalSocket(socket, true);
    Method method = this.socks5Client.negotiateMethod(sock);
    MethodEncapsulation methodEncapsulation = this.socks5Client.doMethodSubnegotiation(method, sock);
    Socket sck = methodEncapsulation.getSocket();
    Socks5Request socks5Req = Socks5Request.newInstance(Command.RESOLVE, host, 0);
    this.socks5Client.sendSocks5Request(socks5Req, sck);
    Socks5Reply socks5Rep = null;
    try {
        socks5Rep = this.socks5Client.receiveSocks5Reply(sck);
    } catch (FailureSocks5ReplyException e) {
        Reply reply = e.getFailureSocks5Reply().getReply();
        if (reply.equals(Reply.HOST_UNREACHABLE)) {
            throw new UnknownHostException(host);
        } else {
            throw e;
        }
    }
    InetAddress inetAddress = InetAddress.getByName(socks5Rep.getServerBoundAddress());
    return InetAddress.getByAddress(host, inetAddress.getAddress());
}
Also used : MethodEncapsulation(com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) UnknownHostException(java.net.UnknownHostException) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) AddressType(com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Aggregations

Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)6 MethodSubnegotiationResults (com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)3 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)3 Method (com.github.jh3nd3rs0n.jargyle.transport.socks5.Method)2 Socket (java.net.Socket)2 Properties (com.github.jh3nd3rs0n.jargyle.client.Properties)1 Route (com.github.jh3nd3rs0n.jargyle.server.Route)1 WorkerContext (com.github.jh3nd3rs0n.jargyle.server.WorkerContext)1 Socks5RequestRoutingRule (com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5RequestRoutingRule)1 AddressType (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType)1 AddressTypeNotSupportedException (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressTypeNotSupportedException)1 CommandNotSupportedException (com.github.jh3nd3rs0n.jargyle.transport.socks5.CommandNotSupportedException)1 MethodEncapsulation (com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation)1 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1