Documentation ¶
Overview ¶
Package checkip defines how to Check an IP address.
Example ¶
package main import ( "encoding/json" "fmt" "net" "github.com/jreisinger/checkip" "github.com/jreisinger/checkip/cli" ) // IsWellKnown implements checkip.Check. func IsWellKnown(ipaddr net.IP) (checkip.Result, error) { res := checkip.Result{Name: "well known"} wellKnown := []net.IP{ net.ParseIP("1.1.1.1"), net.ParseIP("4.4.4.4"), net.ParseIP("8.8.8.8"), } for _, wk := range wellKnown { if string(ipaddr) == string(wk) { res.Info = WellKnown(true) } } return res, nil } // WellKnown implements checkip.Info. type WellKnown bool func (wk WellKnown) Json() ([]byte, error) { return json.Marshal(wk) } func (wk WellKnown) Summary() string { return fmt.Sprintf("%v", wk) } func main() { ipaddr := net.ParseIP("1.1.1.1") results, _ := cli.Run([]checkip.Check{IsWellKnown}, ipaddr) results.PrintSummary() }
Output: well known true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶ added in v0.24.0
Check provides generic and/or security information about an IP address.
type Info ¶ added in v0.24.0
type Info interface { Summary() string // summary info Json() ([]byte, error) // all info in JSON format }
Info is generic information provided by a TypeInfo or TypeInfoSec Check.
type Result ¶ added in v0.7.0
type Result struct { Name string `json:"name"` // check name, max 15 chars Type Type `json:"type"` // check type Malicious bool `json:"malicious"` // provided by TypeSec check type Info Info `json:"info"` }
Result is the information provided by a Check.
Directories ¶
Path | Synopsis |
---|---|
Package check contains functions that can check an IP address.
|
Package check contains functions that can check an IP address. |
Package cli contains functions for running checks from command-line.
|
Package cli contains functions for running checks from command-line. |
cmd
|
|
checkip
Checkip is a command-line tool that provides information on IP addresses.
|
Checkip is a command-line tool that provides information on IP addresses. |
Click to show internal directories.
Click to hide internal directories.