Skip to content

Unofficial golang library and cli tool for MaxMind minFraud.

License

Notifications You must be signed in to change notification settings

evalphobia/minfraud-api-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minfraud-api-go

License: MIT GoDoc Release Build Status Coveralls Coverage Codecov Coverage Go Report Card Code Climate BCH compliance CodeFactor codebeat Scrutinizer Code Quality FOSSA Status

Unofficial golang library for MaxMind minFraud.

Quick Usage for binary

install

Download binary from release page, or build from source:

$ git clone --depth 1 https://github.com/evalphobia/minfraud-api-go.git
$ cd ./minfraud-api-go/cmd
$ go build -o ./minfraud-api-go .

Subcommands

root command

$ minfraud-api-go
Commands:

  help     show help
  single   Exec single api call for minFraud API
  list     Exec api call for minFraud API from csv list file

single command

single command is used to execute single minFraud API call.

./minfraud-api-go single -h
Exec single api call for minFraud API

Options:

  -h, --help      display help information
  -c, --command  *set type of api [score, insights, factors] --command='score'
  -i, --ipaddr    input ip address --ipaddr='8.8.8.8'
  -e, --email     input email address --email='example@example.com'
      --debug     set if you use HTTP debug feature --debug

For example, you can check ip address or email address, or both.

# set auth data
$ export MINFRAUD_ACCOUNT_ID=xxx
$ export MINFRAUD_LICENSE_KEY=yyy

# check ip address
$ ./minfraud-api-go single -c score -i 8.8.8.8

# check email address
$ ./minfraud-api-go single -c insights -e example@example.com

# check combination of ip address and email address
$ ./minfraud-api-go single -c insights -i 8.8.8.8 -e example@example.com

list command

list command is used to execute multiple minFraud API call from list and save risk scores to output file.

./minfraud-api-go list -h
Exec api call for minFraud API from csv list file

Options:

  -h, --help      display help information
  -c, --command  *set type of api [score, insights, factors] --command='score'
  -i, --input    *input csv/tsv file path --input='./input.csv'
  -o, --output   *output tsv file path --output='./output.tsv'
      --debug     set if you use HTTP debug feature --debug

For example, you can check the scores

# set auth data
$ export MINFRAUD_ACCOUNT_ID=xxx
$ export MINFRAUD_LICENSE_KEY=yyy

# prepare CSV/TSV file
$ cat input.tsv
ip_address	email
8.8.8.8	example@example.com
8.8.4.4	example@example.com
1.1.1.1	example@example.com


# check risk from the TSV file
$ ./minfraud-api-go list -c insights -i ./input.tsv -o ./output.tsv
exec #: [2]
exec #: [0]
exec #: [1]

$ cat output.tsv
ip_address	risk_score	ip_risk	ip_is_anonymous	ip_is_anonymous_vpn	ip_is_hosting_provider	ip_is_public_proxyip_is_residential_proxy	ip_is_tor_exit_node	ip_organization	ip_user_count	ip_user_type	ip_country	ip_city	ip_registered_country	ip_represented_country	email_domain_first_seen	email_first_seen	email_is_disposable	email_is_free	email_is_high_risk
8.8.8.8	0.82000	0.01000	false	false	false	false	false	false	Google	25	business	US		USfalse	false	false
8.8.4.4	0.82000	0.01000	false	false	false	false	false	false	Google	5	business	US		USfalse	false	false
1.1.1.1	0.10000	0.01000	false	false	false	false	false	false	Mountain View Communications	20	content_delivery_network	AU		AU				false	false	false

Quick Usage for API

package main

import (
	"fmt"

	"github.com/evalphobia/minfraud-api-go/config"
	"github.com/evalphobia/minfraud-api-go/minfraud"
)

func main() {
	conf := config.Config{
        // you can set auth values to config directly, otherwise used from environment variables.
		AccountID:  "<your MaxMind account id>",
		LicenseKey: "<your MaxMind license key>",
		Debug:      false,
	}

	svc, err := minfraud.New(conf)
	if err != nil {
		panic(err)
	}

	// execute score API
	resp, err := svc.Score(minfraud.BaseRequest{
		Device: &DeviceData{
			IPAddress: "8.8.8.8",
		},
    })
	if err != nil {
		panic(err)
	}
	if resp.HasError() {
		panic(fmt.Errorf("code=[%s] error=[%s]", resp.ErrData.Code, resp.ErrData.Error))
	}

	// just print response in json format
	b, _ := json.Marshal(resp)
	fmt.Printf("%s", string(b))
}

see example dir for more examples, and see official API document for more details (especially request/response).

Environment variables

Name Description
MINFRAUD_ACCOUNT_ID MaxMind Account ID.
MINFRAUD_LICENSE_KEY MaxMind License Key.