Skip to content

Commit bc5bc18

Browse files
committed
fix: dns command bug
1 parent 3b21e1f commit bc5bc18

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

cmd/dnsutils/dns.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
var queryType string
1313

1414
func init() {
15-
DNSCmd.PersistentFlags().StringVarP(&queryType, "type", "t", "A", "query type")
15+
DNSCmd.PersistentFlags().StringVarP(&queryType, "type", "x", "A", "query type")
1616
command.RootCmd.AddCommand(DNSCmd)
1717
}
1818

@@ -40,7 +40,7 @@ var DNSCmd = &cobra.Command{
4040
log.Warnf("Query %s failed: %v", query, err)
4141
continue
4242
}
43-
log.Infof("Query [%d] %s: %v", queryType, query, res)
43+
log.Infof("Query [%s] %s: %v", queryType, query, res)
4444
}
4545
},
4646
}

cmd/root.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6+
"net"
67
"os"
8+
"strings"
79

810
"github.com/esonhugh/k8spider/pkg"
911
log "github.com/sirupsen/logrus"
1012
"github.com/spf13/cobra"
1113
)
1214

1315
var Opts = struct {
14-
Cidr string
16+
Cidr string
17+
PodCidr string
18+
1519
DnsServer string
1620
SvcDomains []string
1721
Zone string
@@ -27,9 +31,24 @@ var Opts = struct {
2731
FilterStrings []string
2832
}{}
2933

34+
func defaultPodCidr() string {
35+
interfaces, _ := net.Interfaces()
36+
for _, i := range interfaces {
37+
if i.Name == "eth0" {
38+
addrs, _ := i.Addrs()
39+
if addrs != nil || len(addrs) > 0 {
40+
ip := strings.Split(addrs[0].String(), "/")[0]
41+
return fmt.Sprintf("%v/16", ip)
42+
}
43+
}
44+
}
45+
return "10.0.0.1/16"
46+
}
47+
3048
func init() {
3149

3250
RootCmd.PersistentFlags().StringVarP(&Opts.Cidr, "cidr", "c", os.Getenv("KUBERNETES_SERVICE_HOST")+"/16", "cidr like: 192.168.0.1/16")
51+
RootCmd.PersistentFlags().StringVarP(&Opts.PodCidr, "pod-cidr", "p", defaultPodCidr(), "pod cidr list, watch out for the network interface name, default is eth0")
3352

3453
RootCmd.PersistentFlags().StringVarP(&Opts.DnsServer, "dns-server", "d", "", "dns server")
3554
RootCmd.PersistentFlags().IntVarP(&pkg.DnsTimeout, "dns-timeout", "i", 2, "dns timeout")

0 commit comments

Comments
 (0)