001/**
002 *
003 * Copyright 2019 Florian Schmaus
004 *
005 * This file is part of smack-repl.
006 *
007 * smack-repl is free software; you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as published by
009 * the Free Software Foundation; either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
020 */
021package org.igniterealtime.smack.smackrepl;
022
023import java.io.IOException;
024
025import org.jivesoftware.smack.SmackConfiguration;
026import org.jivesoftware.smack.SmackException;
027import org.jivesoftware.smack.XMPPException;
028import org.jivesoftware.smack.debugger.ConsoleDebugger;
029import org.jivesoftware.smack.tcp.XMPPTCPConnection;
030import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
031
032import org.jivesoftware.smackx.dox.DnsOverXmppManager;
033import org.jivesoftware.smackx.dox.resolver.minidns.DnsOverXmppMiniDnsResolver;
034
035import org.jxmpp.jid.Jid;
036import org.jxmpp.jid.impl.JidCreate;
037import org.minidns.dnsmessage.DnsMessage;
038import org.minidns.dnsmessage.Question;
039import org.minidns.record.Record;
040
041public class DoX {
042
043    public static void main(String[] args) throws XMPPException, SmackException, IOException, InterruptedException {
044        SmackConfiguration.DEBUG = true;
045
046        XMPPTCPConnection connection = new XMPPTCPConnection(args[0], args[1]);
047        connection.setReplyTimeout(60000);
048
049        connection.connect().login();
050
051        DnsOverXmppManager dox = DnsOverXmppManager.getInstanceFor(connection);
052
053        Jid target = JidCreate.from("dns@moparisthebest.com/listener");
054        Question question = new Question("geekplace.eu", Record.TYPE.A);
055
056        DnsMessage response = dox.query(target, question);
057
058        // CHECKSTYLE:OFF
059        System.out.println(response);
060        // CHECKSTYLE:ON
061
062        connection.disconnect();
063    }
064
065    public static XMPPTCPConnection runDoxResolver(String jid, String password)
066            throws XMPPException, SmackException, IOException, InterruptedException {
067        XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
068                .setXmppAddressAndPassword(jid, password)
069                .setResource("dns")
070                .setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE)
071                .build();
072        XMPPTCPConnection connection = new XMPPTCPConnection(config);
073
074        connection.connect().login();
075
076        DnsOverXmppManager dox = DnsOverXmppManager.getInstanceFor(connection);
077        dox.setDnsOverXmppResolver(DnsOverXmppMiniDnsResolver.INSTANCE);
078
079        dox.enable();
080
081        return connection;
082    }
083}