查询 DNS 垃圾邮件服务无法与 DNSJava 正常工作



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

在这个for语句中,我为每个黑名单做一个查询

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上是blacklisten,但在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的实例,我已经添加了一个其他记录[i]. tostring()。这就是urlib

的输出

checkMailBlacklist, Lookup参数: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 font: multi.uribl.com sito:buyapprove.com

您的代码看起来不错。可能是你的if/else if语句没有考虑到Record的其他子类。尝试替换

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

String rdata = records[i].rdataToString();

相关内容

  • 没有找到相关文章

最新更新