JDIG is a Java library that can be added to your project in order to provide an easy way to do DNS queries.
It also supports DNS-based Blackhole List (DNSBL) / Real-time Blackhole List (RBL) queries. What is this?
It is built with:
- Java 7
- Maven
- SLF4J
- JUnit
0.0.2
http://mvnrepository.com/artifact/com.github.ecolabardini/jdig/0.0.2
A, NS, MX, SRV, TXT, CNAME or Type.any()
The DnsService object can be constructed with several arguments, please see the examples below or check the javadoc for full explanation.
import java.util.List;
import com.jdig.model.DnsEntry;
import com.jdig.model.Type;
import com.jdig.service.DnsService;
(...)
// Simple DnsService
List<DnsEntry> entries = new DnsService().lookup("google.com", Type.any());
(...)
// Query at Google DNS Servers - 8.8.8.8
// The port can also be provided, e.g.: 8.8.8.8:53
List<DnsEntry> entries = new DnsService("8.8.8.8").lookup("google.com", Type.MX);
JDIG uses the underlying JNDI directory service so you can provide your own environment properties, e.g.:
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import com.jdig.model.DnsEntry;
import com.jdig.model.Type;
import com.jdig.service.DnsService;
(...)
Properties environment = new Properties();
environment.put(Context.PROVIDER_URL, "dns://8.8.8.8:53");
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
List<DnsEntry> entries = new DnsService(environment).lookup("google.com", Type.MX);
These queries are provided by the blackListLookup()
method. Note that the DNS blacklist is a mandatory argument.
For DNS blacklists click here.
In the example below, we are checking if the IP address 1.2.3.4 is in the SORBS list.
(...)
List<DnsEntry> blacklistLookup = new DnsService().blacklistLookup("1.2.3.4", "dnsbl.sorbs.net");
To understand SORBS return codes, check Using SORBS.
Note that each list has its own return codes so you should check their webpages.
Please contact me if you have any ideas, suggestions or, even better, you want to collaborate on this project!
This library is licensed under the Apache License, Version 2.0.