Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xbill解析Java中的SRV记录。正确的查询字符串?_Java_Dns_Port_Lookup_Srv - Fatal编程技术网

使用xbill解析Java中的SRV记录。正确的查询字符串?

使用xbill解析Java中的SRV记录。正确的查询字符串?,java,dns,port,lookup,srv,Java,Dns,Port,Lookup,Srv,我正在尝试使用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 P

我正在尝试使用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”;//输入的字符串,我需要获取要添加到此的端口
ArrayList ret=新的ArrayList();
字符串查询=“\u rdp.\u tcp.”+s;
试一试{
记录[]记录=新查找(查询,类型.SRV).run();//返回null
if(records!=null&&records.length>0){
用于(记录r:记录){
SRVRecord srv=(SRVRecord)r;
字符串hostname=srv.getTarget().toString().replaceFirst(“\\.$”,”);
int-port=srv.getPort();
ret.add(主机名+”:“+端口);
}
返回ret;
}
否则{
返回null;
}
}catch(textparse异常){
返回null;
}
new Lookup()返回null,因此我假设传递的查询字符串无效。我需要对查询字符串或SRV记录进行哪些更改才能使其正常工作

使用namescape作为域


谢谢

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

因此,查询将是
\u rdp.\u tcp.example.com

这可以通过在上进行测试来验证,但是使用org.xbill.DSN.Lookup将不起作用

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

    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;
    }