Skip to content

Commit 86d1dc1

Browse files
committed
Add ipdata.co ipinfo.io minfraud
1 parent 6997272 commit 86d1dc1

24 files changed

+1514
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build and update release assets
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
required: true
11+
description: 'version to update release assets'
12+
default: 'v'
13+
14+
jobs:
15+
assets:
16+
runs-on: ubuntu-latest
17+
steps:
18+
19+
- name: Set up Go 1.17
20+
uses: actions/setup-go@v1
21+
with:
22+
go-version: 1.17
23+
id: go
24+
25+
- name: Check out code
26+
uses: actions/checkout@v1
27+
28+
- name: Get tag version
29+
id: tag
30+
run: |
31+
TAG=${{ github.event.inputs.command }}
32+
test -z "$TAG" && TAG=$(git tag --sort=-v:refname --points-at HEAD | head -n 1)
33+
echo "TAG=$TAG" >> $GITHUB_ENV
34+
- name: Cross compile
35+
run: make build-all
36+
37+
- name: Upload assets to the release
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
export GOPATH=$(go env GOPATH)
42+
go get -u github.com/tcnksm/ghr
43+
echo "Upload version [${{ env.TAG }}]"
44+
${GOPATH}/bin/ghr -replace ${{ env.TAG }} bin/release

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
*.csv
18+
*.tsv
19+
bin/*

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.PHONY: init lint build build-macos build-linux build-all clean
2+
3+
GO111MODULE=on
4+
LINT_OPT := -E gofmt \
5+
-E golint \
6+
-E govet \
7+
-E gosec \
8+
-E unused \
9+
-E gosimple \
10+
-E structcheck \
11+
-E varcheck \
12+
-E ineffassign \
13+
-E deadcode \
14+
-E typecheck \
15+
-E misspell \
16+
-E whitespace \
17+
-E errcheck \
18+
--exclude '(comment on exported (method|function|type|const|var)|should have( a package)? comment|comment should be of the form)' \
19+
--timeout 5m
20+
21+
init:
22+
go mod download
23+
24+
lint:
25+
@type golangci-lint > /dev/null || go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
26+
golangci-lint $(LINT_OPT) run ./...
27+
28+
# build binary
29+
build:
30+
go build -o bin/go-ip-fraud-check ./cmd
31+
32+
build-macos:
33+
@make _build BUILD_OS=darwin BUILD_ARCH=amd64
34+
35+
build-macos-m1:
36+
@make _build BUILD_OS=darwin BUILD_ARCH=arm64
37+
38+
build-linux:
39+
@make _build BUILD_OS=linux BUILD_ARCH=amd64
40+
41+
build-windows:
42+
@make _build BUILD_OS=windows BUILD_ARCH=amd64
43+
44+
_build:
45+
@mkdir -p bin/release
46+
$(eval BUILD_OUTPUT := go-ip-fraud-check_${BUILD_OS}_${BUILD_ARCH}${BUILD_ARM})
47+
GOOS=${BUILD_OS} \
48+
GOARCH=${BUILD_ARCH} \
49+
GOARM=${BUILD_ARM} \
50+
go build -o bin/${BUILD_OUTPUT} ./cmd
51+
@if [ "${USE_ARCHIVE}" = "1" ]; then \
52+
gzip -k -f bin/${BUILD_OUTPUT} ;\
53+
mv bin/${BUILD_OUTPUT}.gz bin/release/ ;\
54+
fi
55+
56+
build-all: clean
57+
@make build-macos build-macos-m1 build-linux build-windows USE_ARCHIVE=1
58+
59+
clean:
60+
rm -f bin/go-ip-fraud-check_*
61+
rm -f bin/release/*

README.md

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
go-ip-fraud-check
2+
----
3+
4+
[![License: MIT][401]][402] [![GoDoc][101]][102] [![Release][103]][104] [![Build Status][201]][202] [![Coveralls Coverage][203]][204] [![Codecov Coverage][205]][206]
5+
[![Go Report Card][301]][302] [![Code Climate][303]][304] [![BCH compliance][305]][306] [![CodeFactor][307]][308] [![codebeat][309]][310] [![Scrutinizer Code Quality][311]][312] [![FOSSA Status][403]][404]
6+
7+
8+
<!-- Basic -->
9+
10+
[101]: https://godoc.org/github.com/evalphobia/go-ip-fraud-check?status.svg
11+
[102]: https://godoc.org/github.com/evalphobia/go-ip-fraud-check
12+
[103]: https://img.shields.io/github/release/evalphobia/go-ip-fraud-check.svg
13+
[104]: https://github.com/evalphobia/go-ip-fraud-check/releases/latest
14+
[105]: https://img.shields.io/github/downloads/evalphobia/go-ip-fraud-check/total.svg?maxAge=1800
15+
[106]: https://github.com/evalphobia/go-ip-fraud-check/releases
16+
[107]: https://img.shields.io/github/stars/evalphobia/go-ip-fraud-check.svg
17+
[108]: https://github.com/evalphobia/go-ip-fraud-check/stargazers
18+
19+
20+
<!-- Testing -->
21+
22+
[201]: https://github.com/evalphobia/go-ip-fraud-check/workflows/test/badge.svg
23+
[202]: https://github.com/evalphobia/go-ip-fraud-check/actions?query=workflow%3Atest
24+
[203]: https://coveralls.io/repos/evalphobia/go-ip-fraud-check/badge.svg?branch=master&service=github
25+
[204]: https://coveralls.io/github/evalphobia/go-ip-fraud-check?branch=master
26+
[205]: https://codecov.io/gh/evalphobia/go-ip-fraud-check/branch/master/graph/badge.svg
27+
[206]: https://codecov.io/gh/evalphobia/go-ip-fraud-check
28+
29+
30+
<!-- Code Quality -->
31+
32+
[301]: https://goreportcard.com/badge/github.com/evalphobia/go-ip-fraud-check
33+
[302]: https://goreportcard.com/report/github.com/evalphobia/go-ip-fraud-check
34+
[303]: https://codeclimate.com/github/evalphobia/go-ip-fraud-check/badges/gpa.svg
35+
[304]: https://codeclimate.com/github/evalphobia/go-ip-fraud-check
36+
[305]: https://bettercodehub.com/edge/badge/evalphobia/go-ip-fraud-check?branch=master
37+
[306]: https://bettercodehub.com/
38+
[307]: https://www.codefactor.io/repository/github/evalphobia/go-ip-fraud-check/badge
39+
[308]: https://www.codefactor.io/repository/github/evalphobia/go-ip-fraud-check
40+
[309]: https://codebeat.co/badges/142f5ca7-da37-474f-9264-f708ade08b5c
41+
[310]: https://codebeat.co/projects/github-com-evalphobia-go-ip-fraud-check-master
42+
[311]: https://scrutinizer-ci.com/g/evalphobia/go-ip-fraud-check/badges/quality-score.png?b=master
43+
[312]: https://scrutinizer-ci.com/g/evalphobia/go-ip-fraud-check/?branch=master
44+
45+
<!-- License -->
46+
[401]: https://img.shields.io/badge/License-MIT-blue.svg
47+
[402]: LICENSE.md
48+
[403]: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fevalphobia%2Fgo-ip-fraud-check.svg?type=shield
49+
[404]: https://app.fossa.com/projects/git%2Bgithub.com%2Fevalphobia%2Fgo-ip-fraud-check?ref=badge_shield
50+
51+
52+
go-ip-fraud-check has a feature to detect fraud from ip addresss.
53+
54+
go-ip-fraud-check provides both of cli binary and golang API.
55+
56+
# Supported Providers
57+
58+
- [ipdata.co](https://ipdata.co/)
59+
- [ipinfo.io](https://ipinfo.io/)
60+
- [MaxMind minFraud](https://www.maxmind.com/en/solutions/minfraud-services/)
61+
62+
# Quick Usage for binary
63+
64+
## install
65+
66+
Download binary from release page, or build from source:
67+
68+
```bash
69+
$ git clone --depth 1 https://github.com/evalphobia/go-ip-fraud-check.git
70+
$ cd ./go-ip-fraud-check/cmd
71+
$ go build -o ./go-ip-fraud-check .
72+
```
73+
74+
## Subcommands
75+
76+
### root command
77+
78+
```bash
79+
$ go-ip-fraud-check
80+
Commands:
81+
82+
help show help
83+
single Exec api call of ip address fraud check providers for single ip
84+
list Exec api call of ip address fraud check providers from csv list file
85+
```
86+
87+
### single command
88+
89+
`single` command is used to check single ip address.
90+
91+
```bash
92+
./go-ip-fraud-check single -h
93+
94+
Exec api call of ip address fraud check providers for single ip
95+
96+
Options:
97+
98+
-h, --help display help information
99+
-p, --provider *set types of api provider (space separated) --provider='ipdata ipinfo minfraud'
100+
-i, --ip input ip address --ip='8.8.8.8'
101+
--debug set if you need verbose logs --debug
102+
```
103+
104+
For example, you can check ip address like below
105+
106+
```bash
107+
# set auth data
108+
$ export FRAUD_CHECK_IPDATACO_APIKEY=xxx
109+
$ export FRAUD_CHECK_IPINFOIO_TOKEN=yyy
110+
111+
# check ip address
112+
$ ./go-ip-fraud-check single -p 'ipdata ipinfo' -i 8.8.8.8
113+
114+
2021/10/25 00:54:26 [INFO] [INFO] Use ipdata.co
115+
2021/10/25 00:54:26 [INFO] [INFO] Use ipinfo.io
116+
{"list":[{"service_name":"ipdata.co","ip":"8.8.8.8","hostname":"","isp":"Google LLC","organization":"","asn":15169,"risk_score":0,"is_anonymous":false,"is_anonymous_vpn":false,"is_hosting":false,"is_proxy":false,"is_tor":false,"is_bot":false,"is_bogon":false,"has_other_threat":false,"country":"US","city":"","region":"","latitude":0,"longitude":0,"error":""},{"service_name":"ipinfo.io","ip":"8.8.8.8","hostname":"dns.google","isp":"","organization":"Google LLC","asn":15169,"risk_score":0,"is_anonymous":false,"is_anonymous_vpn":false,"is_hosting":false,"is_proxy":false,"is_tor":false,"is_bot":false,"is_bogon":false,"has_other_threat":false,"country":"US","city":"Mountain View","region":"California","latitude":37.4056,"longitude":-122.0775,"error":""}]}
117+
```
118+
119+
### list command
120+
121+
`list` command is used to check multiple ip address from list and save results to output file.
122+
123+
```bash
124+
./go-ip-fraud-check list -h
125+
Exec api call of ip address fraud check providers from csv list file
126+
127+
Options:
128+
129+
-h, --help display help information
130+
-p, --provider *set types of api provider (space separated) --provider='ipdata ipinfo minfraud'
131+
-i, --input *input csv/tsv file path --input='./input.csv'
132+
-o, --output *output tsv file path --output='./output.tsv'
133+
--debug set if you use HTTP debug feature --debug
134+
```
135+
136+
For example, you can check ip address from csv list like below
137+
138+
```bash
139+
# set auth data
140+
$ export FRAUD_CHECK_IPDATACO_APIKEY=xxx
141+
$ export FRAUD_CHECK_IPINFOIO_TOKEN=yyy
142+
143+
# prepare CSV file
144+
$ cat input.csv
145+
ip_address
146+
8.8.8.8
147+
8.8.4.4
148+
1.1.1.1
149+
150+
151+
# check risk from the CSV file
152+
$ ./go-ip-fraud-check list -p 'ipdata ipinfo' -i ./input.csv -o ./output.tsv
153+
2021/10/25 00:58:29 [INFO] [INFO] Use ipdata.co
154+
2021/10/25 00:58:29 [INFO] [INFO] Use ipinfo.io
155+
2021/10/25 00:58:30 [INFO] exec #: [2]
156+
2021/10/25 00:58:29 [INFO] exec #: [0]
157+
2021/10/25 00:58:31 [INFO] exec #: [1]
158+
159+
$ cat output.tsv
160+
service ip_address hostname risk_score isp organization asn country city region latitude longitude is_anonymous is_anonymous_vpn is_hosting is_proxy is_tor is_bot is_bogon has_other_threat
161+
ipdata.co 8.8.8.8 0.00000 Google LLC 15169 US 0.00000 0.00000 false false false false false false false false
162+
ipinfo.io 8.8.8.8 dns.google 0.00000 Google LLC 15169 US Mountain View California 37.40560 -122.07750 false false false false false false false false
163+
ipdata.co 8.8.4.4 0.00000 Google LLC 15169 US 0.00000 0.00000 false false false false false false false false
164+
ipinfo.io 8.8.4.4 dns.google 0.00000 Google LLC 15169 US Mountain View California 37.40560 -122.07750 false false false false false false false false
165+
ipdata.co 1.1.1.1 0.00000 Cloudflare, Inc. 13335 AU 0.00000 0.00000 false false false false false false false false
166+
ipinfo.io 1.1.1.1 one.one.one.one 0.00000 Cloudflare, Inc. 13335 US San Francisco California37.76210 -122.39710 false false true false false false false false
167+
```
168+
169+
# Quick Usage for API
170+
171+
```go
172+
package main
173+
174+
import (
175+
"fmt"
176+
177+
"github.com/evalphobia/go-ip-fraud-check/ipfraudcheck"
178+
"github.com/evalphobia/go-ip-fraud-check/provider"
179+
"github.com/evalphobia/go-ip-fraud-check/provider/ipdataco"
180+
"github.com/evalphobia/go-ip-fraud-check/provider/ipinfoio"
181+
)
182+
183+
func main() {
184+
conf := ipfraudcheck.Config{
185+
// you can set auth values to config directly, otherwise used from environment variables.
186+
IPdatacoAPIKey: "<your ipdata.co API key>",
187+
IPinfoioToken: "<your ipinfo.io API token>",
188+
Debug: false,
189+
}
190+
191+
svc, err := ipfraudcheck.New(conf, []provider.Provider{
192+
&ipdataco.IPdatacoProvider{},
193+
&ipinfo.IPinfoioProvider{},
194+
})
195+
if err != nil {
196+
panic(err)
197+
}
198+
199+
// execute score API
200+
resp, err := svc.CheckIP("8.8.8.8")
201+
if err != nil {
202+
panic(err)
203+
}
204+
205+
for _, r := range resp.List {
206+
// just print response in json format
207+
b, _ := json.Marshal(r)
208+
fmt.Printf("%s", string(b))
209+
}
210+
}
211+
```
212+
213+
see example dir for more examples.
214+
215+
216+
# Environment variables
217+
218+
| Name | Description |
219+
|:--|:--|
220+
| `FRAUD_CHECK_IPDATACO_APIKEY` | [ipdata.co API key](https://docs.ipdata.co/). |
221+
| `FRAUD_CHECK_IPINFOIO_TOKEN` | [ipinfo.io API token](https://ipinfo.io/developers). |
222+
| `MINFRAUD_ACCOUNT_ID` | [MaxMind Account ID](https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/). |
223+
| `MINFRAUD_LICENSE_KEY` | [MaxMind License Key](https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/). |

0 commit comments

Comments
 (0)