-1

I'm developing a function that queries a list of DNS servers using DNSJava library to check if a specific domain is blacklisted. Here you have the portion of code that make the check. At the end you will find the output of the function; for the test i used a domain that seems to be blacklisten on black.uribl.com: buyapprove.com

In this for i make one query for each blacklist

String mailBlacklistServers[]={"dnsbl.sorbs.net","multi.uribl.com","dbl.spamhaus.org", "multi.surbl.com","bl.spamcop.net"};
boolean blacklisted;
boolean blacklistedFinalResult=false;;
String tempBlacklistedOn="";

for(int i=0;i<mailBlacklistServers.length;i++)
{
    blacklisted=checkMailBlacklist(thisWhoAPIRequest.getWebsite().getWebsiteURLstr(),mailBlacklistServers[i]);
    if(blacklisted==true)
    {
            blacklistedFinalResult=true;
            if(tempBlacklistedOn.isEmpty())
                 tempBlacklistedOn=mailBlacklistServers[i];
            else
                tempBlacklistedOn=tempBlacklistedOn+" "+mailBlacklistServers[i];
    }
}

This function performs the check (buyapprove.com is hardcoded)

private boolean checkMailBlacklist(String url, String servAddr)
{
    String res=new String("buyapprove.com");
    res=res.replace("http://", "");
    res=res.replace("www.", "");
    String dnsblDomain = servAddr;

    Lookup lookup;
    try 
    {
        System.out.println("checkMailBlacklist, Lookup Parameters: "+res+"."+servAddr);
        lookup = new Lookup(res+"."+servAddr, Type.ANY);

        Resolver resolver = new SimpleResolver();
        lookup.setResolver(resolver);
        lookup.setCache(null);
        Record[] records = lookup.run();

        if(lookup.getResult() == Lookup.SUCCESSFUL)
        {
            String responseMessage = null;
            String listingType = null;
            for (int i = 0; i < records.length; i++)
            {
                if(records[i] instanceof TXTRecord)
                {
                    TXTRecord txt = (TXTRecord) records[i];
                    for(Iterator j = txt.getStrings().iterator(); j.hasNext();)
                    {
                        responseMessage += (String)j.next();
                    }
                }
                else if(records[i] instanceof ARecord)
                {
                    listingType = ((ARecord)records[i]).getAddress().getHostAddress();
                }
            }
            System.out.println("checkMailBlacklist, lookup done: \n"+listingType+"\n"+responseMessage+" fonte: "+servAddr+" sito:"+res);
            if(listingType==null)
                return false;
            else
                return true;
        }
        else if(lookup.getResult() == Lookup.HOST_NOT_FOUND)
        {
            System.out.println("checkMailBlacklist, lookup bad: HOST_NOT_FOUND");
            return false;
        }
        else
        {
            System.out.println("checkMailBlacklist, lookup bad: error Lookup="+lookup.getResult());
            return false;
        }
    } catch (TextParseException e) {
        System.out.println("Exc TextParseException in checkMailBlacklist");
        e.printStackTrace();
    } catch (UnknownHostException e) {
        System.out.println("Exc UnknownHostException in checkMailBlacklist");
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}

buyapprove.com is blacklisten on spamhaus but not in multi.uribl.com (setting black.uribl.com changes nothing). The output for multi.uribl.com is

checkMailBlacklist, lookup done: null null fonte: multi.uribl.com sito:buyapprove.com

i don't get any exception, so the query is done correctly. For spamhaus i get a positive

checkMailBlacklist, lookup done: 127.0.1.2 null http://www.spamhaus.org/query/dbl domain=buyapprove.com fonte: dbl.spamhaus.org sito:buyapprove.com

Am i doing something wrong?

EDIT: if record[i] if not an instance of TXTRecord or ARecord, i've added a else record[i].toString(). That's the output for uribl

checkMailBlacklist, Lookup Parameters: buyapprove.com.multi.uribl.com

Stampa extra del record: buyapprove.com.multi.uribl.com.fastwebnet.it. 28635 IN MX 10 mx2.fastwebnet.it.

Stampa extra del record: buyapprove.com.multi.uribl.com.fastwebnet.it. 28635 IN MX 10 mx4.fastwebnet.it.

Stampa extra del record: buyapprove.com.multi.uribl.com.fastwebnet.it. 28635 IN MX 10 mx3.fastwebnet.it.

Stampa extra del record: buyapprove.com.multi.uribl.com.fastwebnet.it. 28635 IN MX 10 mx1.fastwebnet.it.

checkMailBlacklist, lookup done: null null fonte: multi.uribl.com sito:buyapprove.com

mark
  • 939
  • 2
  • 13
  • 36
  • 1
    What's the instance type of `records[i]` for the case of `multi.uribl.com`? Maybe you need to add another `else` statement since [`Record`](http://www.xbill.org/dnsjava/dnsjava-current/doc/org/xbill/DNS/Record.html) has more than two sub-classes. – ivan.sim Aug 24 '14 at 07:40

1 Answers1

2

Your codes look right. It could be that your if/else if statement didn't account for the other sub-classes of Record. Try replace

if(records[i] instanceof TXTRecord)
{
    // .....
}
else if(records[i] instanceof ARecord)
{
    // ....
}

with

String rdata = records[i].rdataToString();
ivan.sim
  • 8,972
  • 8
  • 47
  • 63
  • printing all records[i] using rdataToString() i get four lines like "10 mx2.fastwebnet.it.", where only the 3rd numeric-char after "mx" changes. For spamhaus (the only that shows a positive) i get only two records: the first one is ""http://www.spamhaus.org/query/dbl?domain=buyapprove.com"", the second one is "127.0.1.2" – mark Aug 24 '14 at 08:14
  • So looks like the `rdataToString()` method is doing the same thing as `toString()`. And aren't the responses you now get from uribl showing a positive? – ivan.sim Aug 24 '14 at 08:21
  • what would be a positive look like then? – ivan.sim Aug 24 '14 at 11:29
  • If your question is solved with the help of others, then it would be polite to post your solution. – Hontvári Levente Mar 08 '15 at 14:33