lookup

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LookupCmd = &cobra.Command{
	Use:   "lookup <ip>",
	Short: "Lookup IP geolocation information",
	Long:  "Lookup geographic information for a given IP address using MaxMind GeoIP databases. Supports both IPv4 and IPv6 addresses.",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		ip := args[0]

		mmClient := maxmind.NewClient(&config.Current.MaxMind, config.Current.Core.DataDir)
		if err := mmClient.Load(); err != nil {
			return fmt.Errorf("failed to load MaxMind databases: %w", err)
		}

		record, err := mmClient.IP2Geo(ip)
		if err != nil {
			return fmt.Errorf("error fetching record: %w", err)
		}

		b, err := json.MarshalIndent(record, "", "    ")
		if err != nil {
			return fmt.Errorf("error parsing record: %w", err)
		}

		cmd.Println(string(b))
		return nil
	},
	SilenceUsage: true,
}

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