From b98e525016648e5c5760d09bdec7c187ae090425 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Tue, 21 Apr 2020 12:01:26 -0700 Subject: [PATCH] Change SRV lookup code to use dnsjava. --- pom.xml | 11 +++++++++ .../packetlib/tcp/TcpClientSession.java | 24 +++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index a9168ef1..ba13d261 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,17 @@ 4.1.45.Final compile + + dnsjava + dnsjava + 3.0.2 + + + + org.slf4j + slf4j-nop + 1.7.30 + diff --git a/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java b/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java index fdbe422d..7f993781 100644 --- a/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java +++ b/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java @@ -15,10 +15,11 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.proxy.HttpProxyHandler; import io.netty.handler.proxy.Socks4ProxyHandler; import io.netty.handler.proxy.Socks5ProxyHandler; -import io.netty.util.concurrent.Future; - -import javax.naming.directory.InitialDirContext; -import java.util.Hashtable; +import org.xbill.DNS.Lookup; +import org.xbill.DNS.Record; +import org.xbill.DNS.SRVRecord; +import org.xbill.DNS.TextParseException; +import org.xbill.DNS.Type; public class TcpClientSession extends TcpSession { private Client client; @@ -104,17 +105,14 @@ public class TcpClientSession extends TcpSession { int port = getPort(); try { - Hashtable environment = new Hashtable(); - environment.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); - environment.put("java.naming.provider.url", "dns:"); + Record[] records = new Lookup(getPacketProtocol().getSRVRecordPrefix() + "._tcp." + host, Type.SRV).run(); + if(records.length > 0) { + SRVRecord srv = (SRVRecord) records[0]; - String[] result = new InitialDirContext(environment).getAttributes(getPacketProtocol().getSRVRecordPrefix() + "._tcp." + host, new String[] {"SRV"}).get("srv").get().toString().split(" ", 4); - host = result[3]; - port = Integer.parseInt(result[2]); - if(host.endsWith(".")) { - host = host.substring(0, host.length() - 1); + host = srv.getTarget().toString().replaceFirst("\\.$", ""); + port = srv.getPort(); } - } catch(Throwable t) { + } catch(TextParseException e) { } bootstrap.remoteAddress(host, port);