我正在开发一个函数,该函数使用DNSJava库查询DNS服务器列表,以检查特定域是否被列入黑名单。在这里,你有一部分代码可以进行检查。最后你会发现函数的输出;对于测试,我在black.uribl.com上使用了似乎是blacklisten的域名: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上是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的实例,我添加了一个else记录[i] .toString()。这是uribl的输出
checkMailBlacklist,查询参数: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,查找完成:null null fonte:multi.uribl.com sito:buyapprove.com
答案 0 :(得分:2)
您的代码看起来正确。可能是您的if/else if
声明未考虑Record
的其他子类。尝试替换
if(records[i] instanceof TXTRecord)
{
// .....
}
else if(records[i] instanceof ARecord)
{
// ....
}
与
String rdata = records[i].rdataToString();