-1

我正在开发一个函数,该函数使用 DNSJava 库查询 DNS 服务器列表,以检查特定域是否被列入黑名单。在这里,您有进行检查的代码部分。最后你会找到函数的输出;对于测试,我使用了一个似乎在 black.uribl.com 上被黑名单的域:buyapprove.com

在这我为每个黑名单做一个查询

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];
    }
}

此函数执行检查(buyapprove.com 是硬编码的)

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 在 spamhaus 上被黑名单,但在 multi.uribl.com 中没有(设置 black.uribl.com 不会改变任何内容)。multi.uribl.com 的输出是

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

我没有得到任何异常,因此查询已正确完成。对于 spamhaus,我得到了肯定

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

难道我做错了什么?

编辑:如果记录 [i] 如果不是 TXTRecord 或 ARecord 的实例,我添加了一个 else 记录 [i].toString()。这是uribl的输出

checkMailBlacklist,查找参数:buyapprove.com.multi.uribl.com

邮票额外删除记录:buyapprove.com.multi.uribl.com.fastwebnet.it。28635 IN MX 10 mx2.fastwebnet.it。

邮票额外删除记录:buyapprove.com.multi.uribl.com.fastwebnet.it。28635 IN MX 10 mx4.fastwebnet.it。

邮票额外删除记录:buyapprove.com.multi.uribl.com.fastwebnet.it。28635 IN MX 10 mx3.fastwebnet.it。

邮票额外删除记录:buyapprove.com.multi.uribl.com.fastwebnet.it。28635 IN MX 10 mx1.fastwebnet.it。

checkMailBlacklist,查找完成:null null fonte:multi.uribl.com sato:buyapprove.com

4

1 回答 1

2

您的代码看起来正确。可能是您的if/else if陈述没有考虑Record. 尝试更换

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

String rdata = records[i].rdataToString();
于 2014-08-24T07:57:50.523 回答