ip_local

package
v0.77.0-dev-1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:     "ip-local",
	Short:   "Get local IP from network device",
	Aliases: []string{"ipl"},
	Args:    cobra.NoArgs,
	Run: func(c *cobra.Command, args []string) {
		if FlagInterfaceName == "" {
			ips, err := ip_utils.GetIPFromInterfaces()
			if err != nil {
				log.Fatal(err)
			}
			if FlagJson {
				outJson, err := json.Marshal(map[string]map[string]string{
					"ips": ips,
				})
				if err != nil {
					panic(err)
				}
				fmt.Println(string(outJson))
			} else {
				for interfaceName, ip := range ips {
					fmt.Printf("%s=%s\n", interfaceName, ip)
				}
			}
		} else {
			ip, err := ip_utils.GetIPFromInterface(FlagInterfaceName)
			if err != nil {
				log.Fatal(err)
			}

			if FlagJson {
				outJson, err := json.Marshal(map[string]string{
					"ip": ip,
				})
				if err != nil {
					panic(err)
				}
				fmt.Println(string(outJson))
			} else {
				fmt.Printf("%s\n", ip)
			}
		}
	},
}
View Source
var FlagInterfaceName string
View Source
var FlagJson 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