DNS query in JAVA

后端 未结 3 1286
一整个雨季
一整个雨季 2021-02-20 08:39

I am messing around with DNS services in Java - I am specifically trying to lookup all google.com addresses and display them in an array, similar to running a lookup using nsloo

相关标签:
3条回答
  • 2021-02-20 08:45

    InetAddress doesn't do this, but you can accomplish DNS TXT record lookups in Java via the JNDI DNS provider.

    0 讨论(0)
  • 2021-02-20 08:52

    Here is an example that does what you are trying to do:

    Attribute attr = new InitialDirContext().getAttributes("dns:_netblocks.google.com", new String[] {"TXT"}).get("TXT");
    System.out.println("attr.get() = " + attr.get());
    System.out.println("attr.getAll() = " + Collections.list(attr.getAll()));
    

    If you want to use a custom dns server use "dns://1.1/_netblocks.google.com" instead.

    0 讨论(0)
  • 2021-02-20 09:07

    You cannot lookup TXT or other DNS records InetAddress class. InetAddress.getAllByName() looks up for A, or AAAA records only.

    Check DNS Java for your needs.

    0 讨论(0)
提交回复
热议问题