【问题标题】:Resolving SRV Records in Java using xbill. Correct Query string?使用 xbill 在 Java 中解析 SRV 记录。正确的查询字符串?
【发布时间】:2014-05-29 09:55:04
【问题描述】:

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

谢谢

【问题讨论】:

    标签: java dns port lookup srv


    【解决方案1】:

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

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

    这可以通过在 MXToolbox's SRV lookup 上进行测试来验证,但使用 org.xbill.DSN.Lookup 将无法正常工作。

    查找问题已简化为另一个问题:23935847

    【讨论】:

      猜你喜欢
      • 2014-04-25
      • 1970-01-01
      • 2010-11-14
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多