vpn

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRateLimitReached = errors.New("rate limit reached")
)

Functions

This section is empty.

Types

type IPHub

type IPHub struct {
	// contains filtered or unexported fields
}

IPHub implemets the VPNApi interface and checks whether a given IP is a vpn

func NewIPHub

func NewIPHub(c *http.Client, apikey string) *IPHub

NewIPHub reates a new api that can be checked for VPN IPs

func (*IPHub) Fetch

func (ih *IPHub) Fetch(IP string) (block int, err error)

Fetch :

func (*IPHub) IsVPN

func (ih *IPHub) IsVPN(IP string) (bool, error)

IsVPN tests if a given IP is a VPN IP

func (IPHub) String

func (ih IPHub) String() string

String implements the stringer interface

type ProxyCheck

type ProxyCheck struct {
	// contains filtered or unexported fields
}

ProxyCheck implemets the VPNApi interface and checks whether a given IP is a vpn

func NewProxyCheck

func NewProxyCheck(c *http.Client, apikey string) *ProxyCheck

NewProxyCheck reates a new api that can be checked for VPN IPs

func (*ProxyCheck) Fetch

func (ih *ProxyCheck) Fetch(IP string) (bool, error)

Fetch :

func (*ProxyCheck) IsVPN

func (ih *ProxyCheck) IsVPN(IP string) (bool, error)

IsVPN tests if a given IP is a VPN IP

func (*ProxyCheck) String

func (ih *ProxyCheck) String() string

String implements the stringer interface

type ProxyCheckInfoResponseData

type ProxyCheckInfoResponseData struct {
	Asn        string
	Provider   string
	Continent  string
	Country    string
	Isocode    string
	Region     string
	Regioncode string
	City       string
	Latitude   float32
	Longitude  float32
	Proxy      string
	Type       string
}

responseData : structure of the response from this API (IP information)

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter can be used to limit requests within a specific period of time. initialized with Init(...) and used with Allow()

func NewRateLimiter

func NewRateLimiter(expirationDuration time.Duration, rateLimit int) *RateLimiter

NewRateLimiter initializes the RateLimiter with the current time expirationDuration What is the time duration each token expires in rateLimit is the amount of requests per expirationDiration, like 1000 requests per Day

func (*RateLimiter) Allow

func (r *RateLimiter) Allow() bool

Allow returns true if the rate has not yet been exceeded, returns false otherwise. Info: goroutine safe

type Security added in v0.3.1

type Security struct {
	VPN   bool `json:"vpn"`
	Proxy bool `json:"proxy"`
	Tor   bool `json:"tor"`
	Relay bool `json:"relay"`
}

type VPN

type VPN interface {
	fmt.Stringer
	IsVPN(IP string) (bool, error)
}

VPN API interface. Provides a method to test IPs for whether they are VPNs or not.

type VPNAPI added in v0.3.1

type VPNAPI struct {
	// contains filtered or unexported fields
}

VPNAPI implements the VPNApi and allows to check if an ip is a vpn

func NewVPNAPI added in v0.3.1

func NewVPNAPI(c *http.Client, apiKey string) *VPNAPI

NewVPNAPI creates a new api endpoint that can check IPs for whether they are VPNs or not.

func (*VPNAPI) Fetch added in v0.3.1

func (it *VPNAPI) Fetch(IP string) (bool, error)

Fetch :

func (*VPNAPI) IsVPN added in v0.3.1

func (it *VPNAPI) IsVPN(IP string) (bool, error)

IsVPN requests the api endpoint to test whether an IP is a VPN

func (VPNAPI) String added in v0.3.1

func (it VPNAPI) String() string

String implements the stinger interface

type VPNChecker

type VPNChecker struct {
	Apis      []VPN
	Offline   bool
	Threshold float64
	// contains filtered or unexported fields
}

VPNChecker encapsulates the redis database as cache and the implemented api endpoints in order to determine, whether an ip is a vpn based on either the caching information or based on the implemented api endpoints, whether an ip is a vpn.

func NewVPNChecker

func NewVPNChecker(ctx context.Context, ripr *goripr.Client, vpns []VPN, offline bool, permabanThreshold float64) *VPNChecker

newVPNChecker creates a new checker that can be asked for VPN IPs. it connects to the redis database for caching and requests information from all existing API endpoints that provode free VPN detections.

func (*VPNChecker) Close

func (rdb *VPNChecker) Close() error

func (*VPNChecker) IsVPN

func (rdb *VPNChecker) IsVPN(sIP string) (bool, string, error)

IsVPN checks firstly in cache and then online.

type Valid

type Valid struct {
	IsValid bool
	IsVPN   bool
}

Valid is used to represent the answer of an api endpoint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL