I am trying to obtain SRV records using org.xbill.DNS in java for my domain
I have the following setup on my domain (eg: example.com) at the moment:
Record:
HostName: ramuh
IP Address/URL: 1.1.1.1 // the public ip of my computer
Record Type: A (Address)
And I created the following SRV Record:
_SERVICE : _rdp
_PROTOCOL : _tcp
PRIORITIY : 1
WEIGHT : 1
PORT : 5000
TARGET : ramuh.example.com
The query String i am using:
_rdp._tcp.ramuh.example.com
I would like to be able to get the SRV Record for ramuh.example.com
so i can build:
ramuh.example.com:5000 (that then is translated automatically to 1.1.1.1:5000, not from my side)
Currently using this code (s is the inputted domain for which a list of SRV records needs to be returned):
String s = "ramuh.example.com"; // the inputted string, I need to obtain the Port to be added to this
ArrayList<String> ret = new ArrayList<String>();
String query = "_rdp._tcp." + s;
try{
Record[] records = new Lookup(query,Type.SRV).run(); // returning null
if(records!= null && records.length>0) {
for(Record r : records){
SRVRecord srv = (SRVRecord)r;
String hostname = srv.getTarget().toString().replaceFirst("\\.$","");
int port = srv.getPort();
ret.add(hostname+":"+port);
}
return ret;
}
else{
return null;
}
}catch(TextParseException e){
return null;
}
new Lookup() is returning null so i would assume that the query string being passed is invalid. What changes do i need to carry out on the Query String or SRV Record for this to work?
Using namecheap as a domain.
Thanks
The query does not have to match the target in the SRV record but rather the domain you are using
so the query would be _rdp._tcp.example.com
This can be verified by testing on MXToolbox's SRV lookup however will not work using org.xbill.DSN.Lookup.
The issue with Lookup has been simplified into another question: 23935847