Skip to content

Commit

Permalink
change Name() to String()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Reisinger committed Nov 6, 2021
1 parent 963f42f commit 7e1b679
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion abuseipdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Data struct {
LastReportedAt time.Time `json:"lastReportedAt"`
}

func (a *AbuseIPDB) Name() string { return "abuseipdb.com" }
func (a *AbuseIPDB) String() string { return "abuseipdb.com" }

// Check fills in AbuseIPDB data for a given IP address. It gets the data from
// api.abuseipdb.com/api/v2/check (docs.abuseipdb.com/#check-endpoint).
Expand Down
2 changes: 1 addition & 1 deletion as.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type AS struct {
CountryCode string
}

func (a *AS) Name() string { return "iptoasn.com" }
func (a *AS) String() string { return "iptoasn.com" }

// Check fills in AS data for a given IP address. The data is taken from a TSV
// file ip2asn-combined downloaded from iptoasn.com. The file is created or
Expand Down
2 changes: 1 addition & 1 deletion blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Blocklist struct {
Reports int
}

func (b *Blocklist) Name() string { return "blocklist.de" }
func (b *Blocklist) String() string { return "blocklist.de" }

// Check fills in Bloclist data for a given IP address. It gets the data from
// http://api.blocklist.de
Expand Down
30 changes: 15 additions & 15 deletions checkip.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"github.com/logrusorgru/aurora"
)

// Checker runs a check of an IP address. It also returns its name.
// Checker runs a check of an IP address. String() returns checker's name.
type Checker interface {
Check(ip net.IP) error
Name() string
fmt.Stringer
}

// InfoChecker finds information about an IP address.
Expand All @@ -35,6 +35,17 @@ type SecChecker interface {
Checker
}

// Result holds the result of a check.
type Result struct {
Name string
Type string
Data Checker
Info string
IsMalicious bool
Err error `json:"-"` // omit error from marshalling - https://bit.ly/2ZZOM7C
ErrMsg string
}

// Run runs checkers concurrently checking the ipaddr.
func Run(checkers []Checker, ipaddr net.IP) []Result {
var res []Result
Expand All @@ -51,10 +62,10 @@ func Run(checkers []Checker, ipaddr net.IP) []Result {
}
switch v := c.(type) {
case InfoChecker:
r := Result{Name: v.Name(), Type: "Info", Data: v, Info: v.Info(), Err: err, ErrMsg: errMsg}
r := Result{Name: v.String(), Type: "Info", Data: v, Info: v.Info(), Err: err, ErrMsg: errMsg}
res = append(res, r)
case SecChecker:
r := Result{Name: c.Name(), Type: "Sec", Data: v, IsMalicious: v.IsMalicious(), Err: err, ErrMsg: errMsg}
r := Result{Name: c.String(), Type: "Sec", Data: v, IsMalicious: v.IsMalicious(), Err: err, ErrMsg: errMsg}
res = append(res, r)
}

Expand All @@ -70,17 +81,6 @@ func redactSecrets(s string) string {
return key.ReplaceAllString(s, "${1}=REDACTED")
}

// Result holds the result of a check.
type Result struct {
Name string
Type string
Data Checker
Info string
IsMalicious bool
Err error `json:"-"` // omit error from marshalling - https://bit.ly/2ZZOM7C
ErrMsg string
}

type byName []Result

func (x byName) Len() int { return len(x) }
Expand Down
2 changes: 1 addition & 1 deletion cins.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CINSArmy struct {
CountIPs int
}

func (c *CINSArmy) Name() string { return "cinsscore.com" }
func (c *CINSArmy) String() string { return "cinsscore.com" }

// Check fills in the CINSArmy data.
func (c *CINSArmy) Check(ipaddr net.IP) error {
Expand Down
2 changes: 1 addition & 1 deletion dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type DNS struct {
Names []string
}

func (d *DNS) Name() string { return "net.LookupAddr" }
func (d *DNS) String() string { return "net.LookupAddr" }

// Check does a reverse lookup for a given IP address.
func (d *DNS) Check(ipaddr net.IP) error {
Expand Down
2 changes: 1 addition & 1 deletion et.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ET struct {
CountIPs int
}

func (e *ET) Name() string { return "rules.emergingthreats.net" }
func (e *ET) String() string { return "rules.emergingthreats.net" }

// Check checks whether the ippaddr is not among compromised IP addresses from
// The Emerging Threats Intelligence feed (ET). I found ET mentioned at
Expand Down
2 changes: 1 addition & 1 deletion geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Geo struct {
City, Country, IsoCode string
}

func (g *Geo) Name() string { return "maxmind.com" }
func (g *Geo) String() string { return "maxmind.com" }

// Check fills in the geolocation data. The data is taken from
// GeoLite2-City.mmdb file that gets downloaded and regularly updated.
Expand Down
2 changes: 1 addition & 1 deletion ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type IP struct {
DefaultMask net.IPMask
}

func (i *IP) Name() string { return "net.IP" }
func (i *IP) String() string { return "net.IP" }

// Check fills in IP data.
func (i *IP) Check(ipaddr net.IP) error {
Expand Down
2 changes: 1 addition & 1 deletion ipsum.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type IPsum struct {
NumOfBlacklists int
}

func (ip *IPsum) Name() string { return "github.com/stamparm/ipsum" }
func (ip *IPsum) String() string { return "github.com/stamparm/ipsum" }

// Check checks how many blackists the IP address is found on.
func (ip *IPsum) Check(ipaddr net.IP) error {
Expand Down
2 changes: 1 addition & 1 deletion otx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type OTX struct {
} `json:"pulse_info"`
}

func (otx *OTX) Name() string { return "otx.alienvault.com" }
func (otx *OTX) String() string { return "otx.alienvault.com" }

// Check gets data from https://otx.alienvault.com/api.
func (otx *OTX) Check(ipaddr net.IP) error {
Expand Down
2 changes: 1 addition & 1 deletion shodan.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type data []struct {
Transport string `json:"transport"` // tcp, udp
}

func (s *Shodan) Name() string { return "shodan.io" }
func (s *Shodan) String() string { return "shodan.io" }

// Check fills in Shodan data for a given IP address. Its get the data from
// https://api.shodan.io.
Expand Down
2 changes: 1 addition & 1 deletion threatcrowd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ThreatCrowd struct {
Votes int `json:"votes"`
}

func (t *ThreatCrowd) Name() string { return "threatcrowd.org" }
func (t *ThreatCrowd) String() string { return "threatcrowd.org" }

// Check retrieves information from
// https://www.threatcrowd.org/searchApi/v2/ip/report.
Expand Down
2 changes: 1 addition & 1 deletion virustotal.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type VirusTotal struct {
} `json:"data"`
}

func (vt *VirusTotal) Name() string { return "virustotal.com" }
func (vt *VirusTotal) String() string { return "virustotal.com" }

// Check fills in data about ippaddr from https://www.virustotal.com/api
func (vt *VirusTotal) Check(ipaddr net.IP) error {
Expand Down

0 comments on commit 7e1b679

Please sign in to comment.