Skip to content

Commit

Permalink
pulled out module cli commands into seperate files, fixed NSLOOKUP er…
Browse files Browse the repository at this point in the history
…ror as is in a PR in main
  • Loading branch information
phillip-stephens committed May 8, 2024
1 parent d51acb1 commit c415226
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 44 deletions.
47 changes: 47 additions & 0 deletions cmd/nslookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* ZDNS Copyright 2024 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package cmd

import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zmap/zdns/internal/util"
"github.com/zmap/zdns/pkg/zdns"
)

// nslookupCmd represents the nslookup command
var nslookupCmd = &cobra.Command{
Use: "nslookup",
Short: "Run a more exhaustive nslookup",
Long: `nslookup will additionally do an A/AAAA lookup for the IP addresses that correspond with name server records.`,
Run: func(cmd *cobra.Command, args []string) {
GC.Module = strings.ToUpper("nslookup")
zdns.Run(GC, cmd.Flags(),
&Timeout, &IterationTimeout,
&Class_string, &Servers_string,
&Config_file, &Localaddr_string,
&Localif_string, &NanoSeconds, &ClientSubnet_string, &NSID)
},
}

func init() {
rootCmd.AddCommand(nslookupCmd)

nslookupCmd.PersistentFlags().Bool("ipv4-lookup", false, "perform A lookups for each NS server")
nslookupCmd.PersistentFlags().Bool("ipv6-lookup", false, "perform AAAA record lookups for each NS server")

util.BindFlags(nslookupCmd, viper.GetViper(), util.EnvPrefix)
}
45 changes: 45 additions & 0 deletions pkg/cmd/alookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* ZDNS Copyright 2024 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zmap/zdns/internal/util"
"strings"
)

// alookupCmd represents the alookup command
var alookupCmd = &cobra.Command{
Use: "alookup",
Short: "A record lookups that follow CNAME records",
Long: `alookup will get the information that is typically desired, instead of just
the information that exists in a single record.
Specifically, alookup acts similar to nslookup and will follow CNAME records.`,
Args: cobra.MatchAll(cobra.ExactArgs(0), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
GC.Module = strings.ToUpper("alookup")
Run(GC, cmd.Flags())
},
}

func init() {
rootCmd.AddCommand(alookupCmd)

alookupCmd.PersistentFlags().Bool("ipv4-lookup", false, "perform A lookups for each MX server")
alookupCmd.PersistentFlags().Bool("ipv6-lookup", false, "perform AAAA record lookups for each MX server")

util.BindFlags(alookupCmd, viper.GetViper(), util.EnvPrefix)
}
43 changes: 0 additions & 43 deletions pkg/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,6 @@ ZDNS also includes its own recursive resolution and a cache to further optimize
},
}

// mxlookupCmd represents the mxlookup command
var mxlookupCmd = &cobra.Command{
Use: "mxlookup",
Short: "Run a more exhaustive mxlookup",
Long: `mxlookup will additionally do an A lookup for the IP addresses that
correspond with an exchange record.`,
Run: func(cmd *cobra.Command, args []string) {
GC.Module = strings.ToUpper("mxlookup")
Run(GC, cmd.Flags())
},
}

// alookupCmd represents the alookup command
var alookupCmd = &cobra.Command{
Use: "alookup",
Short: "A record lookups that follow CNAME records",
Long: `alookup will get the information that is typically desired, instead of just
the information that exists in a single record.
Specifically, alookup acts similar to nslookup and will follow CNAME records.`,
Args: cobra.MatchAll(cobra.ExactArgs(0), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
GC.Module = strings.ToUpper("alookup")
Run(GC, cmd.Flags())
},
}

func init() {
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
Expand All @@ -147,19 +117,6 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)

rootCmd.AddCommand(alookupCmd)
rootCmd.AddCommand(mxlookupCmd)

alookupCmd.PersistentFlags().Bool("ipv4-lookup", false, "perform A lookups for each MX server")
alookupCmd.PersistentFlags().Bool("ipv6-lookup", false, "perform AAAA record lookups for each MX server")

mxlookupCmd.PersistentFlags().Bool("ipv4-lookup", false, "perform A lookups for each MX server")
mxlookupCmd.PersistentFlags().Bool("ipv6-lookup", false, "perform AAAA record lookups for each MX server")
mxlookupCmd.PersistentFlags().Int("mx-cache-size", 1000, "number of records to store in MX -> A/AAAA cache")

util.BindFlags(alookupCmd, viper.GetViper(), util.EnvPrefix)
util.BindFlags(mxlookupCmd, viper.GetViper(), util.EnvPrefix)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
Expand Down
44 changes: 44 additions & 0 deletions pkg/cmd/mxlookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* ZDNS Copyright 2024 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package cmd

import (
"github.com/spf13/viper"
"github.com/zmap/zdns/internal/util"
"strings"

"github.com/spf13/cobra"
)

// mxlookupCmd represents the mxlookup command
var mxlookupCmd = &cobra.Command{
Use: "mxlookup",
Short: "Run a more exhaustive mxlookup",
Long: `mxlookup will additionally do an A lookup for the IP addresses that
correspond with an exchange record.`,
Run: func(cmd *cobra.Command, args []string) {
GC.Module = strings.ToUpper("mxlookup")
Run(GC, cmd.Flags())
},
}

func init() {
rootCmd.AddCommand(mxlookupCmd)

mxlookupCmd.PersistentFlags().Bool("ipv4-lookup", false, "perform A lookups for each MX server")
mxlookupCmd.PersistentFlags().Bool("ipv6-lookup", false, "perform AAAA record lookups for each MX server")
mxlookupCmd.PersistentFlags().Int("mx-cache-size", 1000, "number of records to store in MX -> A/AAAA cache")

util.BindFlags(mxlookupCmd, viper.GetViper(), util.EnvPrefix)
}
42 changes: 42 additions & 0 deletions pkg/cmd/nslookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* ZDNS Copyright 2024 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package cmd

import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zmap/zdns/internal/util"
)

// nslookupCmd represents the nslookup command
var nslookupCmd = &cobra.Command{
Use: "nslookup",
Short: "Run a more exhaustive nslookup",
Long: `nslookup will additionally do an A/AAAA lookup for the IP addresses that correspond with name server records.`,
Run: func(cmd *cobra.Command, args []string) {
GC.Module = strings.ToUpper("nslookup")
Run(GC, cmd.Flags())
},
}

func init() {
rootCmd.AddCommand(nslookupCmd)

nslookupCmd.PersistentFlags().Bool("ipv4-lookup", false, "perform A lookups for each NS server")
nslookupCmd.PersistentFlags().Bool("ipv6-lookup", false, "perform AAAA record lookups for each NS server")

util.BindFlags(nslookupCmd, viper.GetViper(), util.EnvPrefix)
}
2 changes: 1 addition & 1 deletion pkg/modules/nslookup/ns_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

func init() {
ns := new(NSLookupModule)
cmd.RegisterLookupModule("NS", ns)
cmd.RegisterLookupModule("NSLOOKUP", ns)
}

type NSLookupModule struct {
Expand Down

0 comments on commit c415226

Please sign in to comment.