3

Given a hostname like "example.com" I want to get its IP-addreses using specific nameserver.

java.net.InetAddress has

 private static InetAddress getByName(String host, InetAddress reqAddr)

which looks like what I need, but the blooper is that method is private.

https://github.com/gilt/scala-srv-dns has

def lookup(serviceName: ServiceName,
         transportProtocol: TransportProtocol,
         dnsSearchPaths: List[String]): Seq[ServiceRecord]

But, again, private method.

So, what lib can I use? And do you have any idea why the libs listed above have these methods private?

ov7a
  • 1,497
  • 4
  • 15
  • 34
  • 2
    Is it private ? http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html#getByName%28java.lang.String%29 – Ved Jul 07 '14 at 13:00
  • 3
    The variant that accepts a nameservice address is private, yes: see [the source here](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/net/InetAddress.java#InetAddress.getByName%28java.lang.String%2Cjava.net.InetAddress%29) – DNA Jul 07 '14 at 13:14

1 Answers1

2

dnsjava was the solution for me (http://www.dnsjava.org/)

def lookup(host: String, nameServer: String): Array[String] = {
  val l = new Lookup(host)
  l.setResolver(new SimpleResolver(nameServer))
  l.run()
  if (l.getResult() == Lookup.SUCCESSFUL)
    l.getAnswers().map(_.rdataToString())
  else
    Array.empty[String]
}
ov7a
  • 1,497
  • 4
  • 15
  • 34