Work without resolv.conf if the nameserver is specified with @...
This commit is contained in:
parent
e7e56ada07
commit
e4a33cd494
13
ex/q/q.go
13
ex/q/q.go
|
@ -47,8 +47,6 @@ func main() {
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
conf, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
|
|
||||||
nameserver := "@" + conf.Servers[0]
|
|
||||||
qtype := uint16(0)
|
qtype := uint16(0)
|
||||||
qclass := uint16(dns.ClassINET)
|
qclass := uint16(dns.ClassINET)
|
||||||
var qname []string
|
var qname []string
|
||||||
|
@ -70,6 +68,8 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nameserver string
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
for i := 0; i < flag.NArg(); i++ {
|
for i := 0; i < flag.NArg(); i++ {
|
||||||
// If it starts with @ it is a nameserver
|
// If it starts with @ it is a nameserver
|
||||||
|
@ -109,6 +109,15 @@ Flags:
|
||||||
qtype = dns.TypeA
|
qtype = dns.TypeA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(nameserver) == 0 {
|
||||||
|
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
nameserver = "@" + conf.Servers[0]
|
||||||
|
}
|
||||||
|
|
||||||
nameserver = string([]byte(nameserver)[1:]) // chop off @
|
nameserver = string([]byte(nameserver)[1:]) // chop off @
|
||||||
// if the nameserver is from /etc/resolv.conf the [ and ] are already
|
// if the nameserver is from /etc/resolv.conf the [ and ] are already
|
||||||
// added, thereby breaking net.ParseIP. Check for this and don't
|
// added, thereby breaking net.ParseIP. Check for this and don't
|
||||||
|
|
Loading…
Reference in New Issue