英文:
golang net module(LookupSRV)
问题
我对golang非常陌生,我对Python有一些经验,但不是在这个水平上。我正在创建一个名为"digall"的应用程序,使用户可以轻松查看域名时的活动DNS记录。
在应用程序中,我正在使用LookupSRV
,但似乎遇到了一些问题:
func srvRecord(query string) {
service := "sipfederationtls"
protocol := "tcp"
fmt.Printf("\n[+] SRV Record(s)\n")
//srvMap := ["sipfederationtls", "autodiscover", "VLMCS"]
cname, addresses, err := net.LookupSRV(service, protocol, query)
if err != nil {
fmt.Printf("[!] This feature is currently under development, thus not ready yet.\n")
}
fmt.Printf("cname : %s \n", cname)
for i := 0; i < len(addresses); i++ {
fmt.Printf("addrs[%d].Target : %s \n", i, addresses[i].Target)
fmt.Printf("addrs[%d].Port : %d \n", i, addresses[i].Port)
fmt.Printf("addrs[%d].Priority : %d \n", i, addresses[i].Priority)
fmt.Printf("addrs[%d].Weight : %d \n", i, addresses[i].Weight)
}
}
如你所见,变量"service"用作SRV记录的前缀。我的问题是,我想检查此记录的多个前缀,即"sipfederationtls"、"autodiscover"和"VLMCS"。
我的问题是:如何使此函数通过这些前缀迅速执行,并返回有效的前缀?(那些出错的前缀将由我的出色错误消息处理)
我知道这是一个初学者问题,就像我说的,我对golang非常陌生。我会感激你们能给我一些建议。
这是应用程序的完整源代码:http://dpaste.com/3X24ZYR
谢谢。
英文:
I'm very new to golang, I have some experience with python but not on this level per say. I am creating an application that's called "digall", making it easy for a user to see active dns-records when checking a domain name.
In the application I am using LookupSRV
, which I seem to have some issues with:
func srvRecord(query string) {
service := "sipfederationtls"
protocol:= "tcp"
fmt.Printf("\n[+] SRV Record(s)\n")
//srvMap := ["sipfederationtls", "autodiscover", "VLMCS"]
cname, addresses, err := net.LookupSRV(service, protocol, query)
if err != nil {
fmt.Printf("[!] This feature is currently under development, thus not ready yet.\n")
}
fmt.Printf("cname : %s \n", cname)
for i := 0; i < len(addresses); i++ {
fmt.Printf("addrs[%d].Target : %s \n", i, addresses[i].Target)
fmt.Printf("addrs[%d].Port : %d \n", i, addresses[i].Port)
fmt.Printf("addrs[%d].Priority : %d \n", i, addresses[i].Priority)
fmt.Printf("addrs[%d].Weight : %d \n", i, addresses[i].Weight)
}
}
As you can see the variable "service" serves as the prefix of the SRV record. My only problem is that i want to check multiple prefixes of this record, namely "sipfederationtls", "autodiscover" and "VLMCS".
What I am asking is; How to i make this function swift through these prefixes and return the ones that work? (the ones that error out will be handled by err by my fantastic error message)
I am aware that this is a noob question, and like I said I am very new to golang. I would appreciate any tips you guys could give me.
Here is the full source of the application: http://dpaste.com/3X24ZYR
Thank you.
答案1
得分: 1
你无法使用LookupSRV
方法同时查询多个服务,就像你不能使用dig
一次查询多个服务一样。
你最好创建一个服务名称的切片:
services := [...]string{"service1", "service2", "service3"}
然后遍历该切片,并为每个服务调用LookupSRV
:
for _, service := range services {
cname, addrs, err := net.LookupSRV(service, "tcp", "your.domain.name")
// 错误处理
}
此外,在遍历查找结果时,最好使用range
关键字:
for _, record := range addrs {
fmt.Printf("目标: %s:%d\n", record.Target, record.Port)
}
英文:
You can't query multiple services at once using LookupSRV
method, as you can't use dig
for querying several services at once.
You better create a slice of the services' names:
services := [...]string{"service1", "service2", "service3")
And then iterate over it and call LookupSRV
for each service:
for _, service := range services {
cname , addrs, err := net.LookupSRV(service, "tcp", "your.domain.name")
// error handlling
}
Also when iterating over the lookup result, it is better to use the range
keyword:
for _, record := range addrs {
fmt.Printf("Target: %s:%d\n", record.Target, record.Port)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论