Package org.xbill.DNS

Examples of org.xbill.DNS.Resolver


   *      the resolved DNS name or in some cases the IP address as a string
   */
  @Override
  public String apply(String hostIp) {
    try {
      Resolver resolver = new ExtendedResolver();
      resolver.setTimeout(timeoutInSeconds);
      resolver.setTCP(true);

      Name name = ReverseMap.fromAddress(hostIp);
      Record record = Record.newRecord(name, Type.PTR, DClass.IN);
      Message response = resolver.send(newQuery(record));

      Record[] answers = response.getSectionArray(Section.ANSWER);
      if (answers.length == 0) {
        LOG.warn("no answer to DNS resolution attempt for "+hostIp+"; using fallback");
        return fallback(hostIp);
View Full Code Here


   * @param hostIp
   * @return
   * @throws IOException
   */
  public static String resolveAddress(String hostIp) throws IOException {
    Resolver res = new ExtendedResolver();
    res.setTimeout(5); // seconds

    Name name = ReverseMap.fromAddress(hostIp);
    int type = Type.PTR;
    int dclass = DClass.IN;
    Record rec = Record.newRecord(name, type, dclass);
    Message query = Message.newQuery(rec);
    Message response = res.send(query);

    Record[] answers = response.getSectionArray(Section.ANSWER);
    if (answers.length == 0)
      return hostIp;
    else {
View Full Code Here

   * @param hostIp
   * @return The resolved DNS name.
   * @throws IOException
   */
  public static String resolveAddress(String hostIp) throws IOException {
    Resolver res = new ExtendedResolver();
    res.setTimeout(5); // seconds

    Name name = ReverseMap.fromAddress(hostIp);
    int type = Type.PTR;
    int dclass = DClass.IN;
    Record rec = Record.newRecord(name, type, dclass);
    Message query = Message.newQuery(rec);
    Message response = res.send(query);

    Record[] answers = response.getSectionArray(Section.ANSWER);
    if (answers.length == 0)
      return hostIp;
    else {
View Full Code Here

     * @param ip, like "192.168.1.1"
     * @return the complete DNS record for that IP.
     */
    @Converter
    public static Record toRecord(String ip) throws IOException {
        Resolver res = new ExtendedResolver();

        Name name = ReverseMap.fromAddress(ip);
        int type = Type.PTR;
        int dclass = DClass.IN;
        Record rec = Record.newRecord(name, type, dclass);
        Message query = Message.newQuery(rec);
        Message response = res.send(query);

        Record[] answers = response.getSectionArray(Section.ANSWER);
        if (answers.length == 0) {
            return null;
        } else {
View Full Code Here

    /**
     * @return a dns resolver pointing to the local fake server
     */
    protected DNSService getDNSServiceFakeServer() {
        Resolver resolver = null;
        try {
            resolver = new SimpleResolver("127.0.0.1");
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        resolver.setPort(FAKE_SERVER_PORT);
        Lookup.setDefaultResolver(resolver);
        Lookup.setDefaultCache(null, DClass.IN);
        Lookup.setDefaultSearchPath(new Name[] {});

        if (dnsTestServer == null) {
View Full Code Here

   * @param hostIp
   * @return The resolved DNS name.
   * @throws IOException
   */
  public static String resolveAddress(String hostIp) throws IOException {
    Resolver res = new ExtendedResolver();
    res.setTimeout(5); // seconds

    Name name = ReverseMap.fromAddress(hostIp);
    int type = Type.PTR;
    int dclass = DClass.IN;
    Record rec = Record.newRecord(name, type, dclass);
    Message query = Message.newQuery(rec);
    Message response = res.send(query);

    Record[] answers = response.getSectionArray(Section.ANSWER);
    if (answers.length == 0) {
      // Fall back to standard Java: in contrast to dnsjava, this also reads /etc/hosts
      return new InetSocketAddress(hostIp, 0).getAddress().getCanonicalHostName();
View Full Code Here

    getMXRecord(domain);
  }
 
  private static void getMXRecord(String name) throws TextParseException, UnknownHostException {
    Lookup lookup = new Lookup(name, Type.MX);
    Resolver resolver = new SimpleResolver();
//    lookup.setResolver(resolver);
//    lookup.setCache(null);
    for (Record dnsRecord: lookup.run()) {
      MXRecord record = (MXRecord)dnsRecord;
      System.out.println(record.getPriority() + " " + record.rdataToString());
View Full Code Here

  }
 
  private MXLookupResult getMXHostsDirectly(String atHost) throws MXResolverException {

    try {
      Resolver resolver = (this.nameserver==null) ? new SimpleResolver() : new SimpleResolver(this.nameserver);

      // try to lookup the MX records
      Lookup lookup = new Lookup(atHost,Type.MX);
      lookup.setResolver(resolver);
      lookup.run();
View Full Code Here

   *      the resolved DNS name or in some cases the IP address as a string
   */
  @Override
  public String apply(String hostIp) {
    try {
      Resolver resolver = new ExtendedResolver();
      resolver.setTimeout(timeoutInSeconds);
      resolver.setTCP(true);

      Name name = ReverseMap.fromAddress(hostIp);
      Record record = Record.newRecord(name, Type.PTR, DClass.IN);
      Message response = resolver.send(newQuery(record));

      Record[] answers = response.getSectionArray(Section.ANSWER);
      if (answers.length == 0) {
        return fallback(hostIp);

View Full Code Here

    /**
     * @return a dns resolver pointing to the local fake server
     */
    @SuppressWarnings("unchecked")
    protected DNSService getDNSServiceFakeServer() {
        Resolver resolver = null;
        try {
            resolver = new SimpleResolver("127.0.0.1");
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        resolver.setPort(FAKE_SERVER_PORT);
        Lookup.setDefaultResolver(resolver);
        Lookup.setDefaultCache(null, DClass.IN);
        Lookup.setDefaultSearchPath(new Name[] {});

        if (dnsTestServer == null) {
View Full Code Here

TOP

Related Classes of org.xbill.DNS.Resolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.