Skip to content

Commit

Permalink
info == nil means check didn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
jreisinger committed Apr 7, 2022
1 parent 8b41355 commit 4d63e09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ virustotal.com --> network: 218.92.0.0/16, SAN: n/a
Malicious --> 63% (5/8) 🚫
```

The CLI tool also supports JSON output.
The CLI tool also supports JSON output. Here we select Sec (1) and InfoSec (2)
check [type](https://pkg.go.dev/github.com/jreisinger/checkip/check#Type) that
returned some info (i.e. they worked). Then we show if they consider the IP
address malicious.

```
$ checkip -j 218.92.0.158 | \
# Select Sec (1) and InfoSec (2) check types that returned some info
# (i.e. they worked) and show if they consider the IP address malicious.
jq -r '.checks[] | select((.type == 1 or .type == 2) and .info != null) | "\(.malicious)\t\(.name)"'
true abuseipdb.com
true blocklist.de
Expand Down
4 changes: 2 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (rs Results) SortByName() {
// PrintInfo prints summary results from Info and InfoSec checkers.
func (rs Results) PrintInfo() {
for _, r := range rs {
if r == (check.Result{}) { // empty struct
if r.Info == nil { // check didn't work
continue
}
if r.Type == check.TypeInfo || r.Type == check.TypeInfoSec {
Expand Down Expand Up @@ -91,7 +91,7 @@ func (rs Results) PrintMalicious() {

func (rs Results) maliciousStats() (total, malicious int, prob float64) {
for _, r := range rs {
if r == (check.Result{}) { // empty struct
if r.Info == nil { // check didn't work
continue
}
if r.Type == check.TypeSec || r.Type == check.TypeInfoSec {
Expand Down

0 comments on commit 4d63e09

Please sign in to comment.