Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Issue 73, support @ #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ func main() {
os.Exit(1)
}

question := getQuestion()

if timeoutStr != "" {
i, err := strconv.Atoi(timeoutStr)
if err != nil {
Expand All @@ -85,18 +83,35 @@ func main() {
}

var server string
if len(os.Args) > 2 {
server = os.Args[2]
} else {
var domain string
if len(os.Args) == 2 {
sysr, err := sysresolv.NewSystemResolvers(nil, 53)
if err != nil {
log.Printf("Cannot get system resolvers: %v", err)
os.Exit(1)
}

server = sysr.Addrs()[0].String()
domain = os.Args[1]
} else {
if os.Args[1][0] == '@' {
if os.Args[2][0] == '@' {
log.Printf("There are two dns servers")
usage()
os.Exit(1)
}
server = os.Args[1][1:]
domain = os.Args[2]
} else if os.Args[2][0] == '@' {
server = os.Args[2][1:]
domain = os.Args[1]
} else {
domain = os.Args[1]
server = os.Args[2]
}
}

question := getQuestion(domain)

var httpVersions []upstream.HTTPVersion
if http3Enabled {
httpVersions = []upstream.HTTPVersion{
Expand Down Expand Up @@ -236,8 +251,7 @@ func getEDNSOpt() (option *dns.EDNS0_LOCAL) {
}

// getQuestion returns a DNS question for the query.
func getQuestion() (q dns.Question) {
domain := os.Args[1]
func getQuestion(domain string) (q dns.Question) {
rrType := getRRType()
qClass := getClass()

Expand Down Expand Up @@ -354,6 +368,8 @@ func getRRType() (rrType uint16) {

func usage() {
_, _ = os.Stdout.WriteString("Usage: dnslookup <domain> <server> [<providerName> <serverPk>]\n")
_, _ = os.Stdout.WriteString(" or: dnslookup @<server> <domain> [<providerName> <serverPk>]\n")
_, _ = os.Stdout.WriteString(" or: dnslookup <domain> @<server> [<providerName> <serverPk>]\n")
_, _ = os.Stdout.WriteString("<domain>: mandatory, domain name to lookup\n")
_, _ = os.Stdout.WriteString("<server>: mandatory, server address. Supported: plain, tcp:// (TCP), tls:// (DOT), https:// (DOH), sdns:// (DNSCrypt), quic:// (DOQ)\n")
_, _ = os.Stdout.WriteString("<providerName>: optional, DNSCrypt provider name\n")
Expand Down