host

package
v0.81.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "host <domain>",
	Short: "Get IP from domain",
	Args:  cobra.ExactArgs(1),
	Run: func(c *cobra.Command, args []string) {
		var ipsStr []string
		ips, err := net.LookupIP(args[0])
		if err != nil {
			log.Fatalln(err)
		}
		for _, ip := range ips {
			ipStr := ip.String()
			if FlagIPv4Only {
				if strings.Contains(ipStr, ":") {
					continue
				}
			}
			if FlagIPv6Only {
				if strings.Contains(ipStr, ".") {
					continue
				}
			}
			ipsStr = append(ipsStr, ipStr)
			if FlagOneAddress {
				break
			}
		}

		if FlagJson {
			outJson, err := json.Marshal(ipsStr)
			if err != nil {
				panic(err)
			}
			fmt.Println(string(outJson))
		} else {
			for _, ip := range ipsStr {
				fmt.Println(ip)
			}
		}
	},
}
View Source
var FlagIPv4Only bool
View Source
var FlagIPv6Only bool
View Source
var FlagJson bool
View Source
var FlagOneAddress bool

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL