0

我正在尝试使用 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 作为域。

谢谢

4

1 回答 1

0

查询不必匹配 SRV 记录中的目标,而是您正在使用的域

所以查询将是 _rdp._tcp.example.com

这可以通过测试MXToolbox 的 SRV 查找来验证,但使用 org.xbill.DSN.Lookup 将无法正常工作。

Lookup 的问题已简化为另一个问题:23935847

于 2014-05-29T15:11:17.040 回答