我正在尝试使用 java 中的 org.xbill.DNS 为我的域获取 SRV 记录
我目前在我的域(例如:example.com)上有以下设置:
记录:
HostName: ramuh
IP Address/URL: 1.1.1.1 // the public ip of my computer
Record Type: A (Address)
我创建了以下 SRV 记录:
_SERVICE : _rdp
_PROTOCOL : _tcp
PRIORITIY : 1
WEIGHT : 1
PORT : 5000
TARGET : ramuh.example.com
我正在使用的查询字符串:
_rdp._tcp.ramuh.example.com
我希望能够获得 ramuh.example.com 的 SRV 记录
所以我可以建立:
ramuh.example.com:5000(然后自动转换为 1.1.1.1:5000,而不是从我这边)
当前使用此代码(s 是需要返回 SRV 记录列表的输入域):
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() 返回 null 所以我会假设正在传递的查询字符串是无效的。我需要对查询字符串或 SRV 记录进行哪些更改才能使其正常工作?
使用 namecheap 作为域。
谢谢