ip2proxy

package module
v0.0.0-...-6cdfd1e Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 16 Imported by: 0

README

Go Report Card PkgGoDev

IP2Proxy Go Package

This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range, search engine robots (SES) and residential (RES). It lookup the proxy IP address from IP2Proxy BIN Data file. This data file can be downloaded at

As an alternative, this package can also call the IP2Proxy Web Service. This requires an API key. If you don't have an existing API key, you can subscribe for one at the below:

https://www.ip2location.com/web-service/ip2proxy

Installation

To install this module type the following:


go get github.com/ip2location/ip2proxy-go/v4

QUERY USING THE BIN FILE

Methods

Below are the methods supported in this package.

Method Name Description
OpenDB Open the IP2Proxy BIN data for lookup.
Close Close and clean up the file pointer.
PackageVersion Get the package version (1 to 11 for PX1 to PX11 respectively).
ModuleVersion Get the module version.
DatabaseVersion Get the database version.
IsProxy Check whether if an IP address was a proxy. Returned value:
  • -1 : errors
  • 0 : not a proxy
  • 1 : a proxy
  • 2 : a data center IP address or search engine robot
GetAll Return the proxy information in an array.
GetProxyType Return the proxy type. Please visit IP2Location for the list of proxy types supported.
GetCountryShort Return the ISO3166-1 country code (2-digits) of the proxy.
GetCountryLong Return the ISO3166-1 country name of the proxy.
GetRegion Return the ISO3166-2 region name of the proxy. Please visit ISO3166-2 Subdivision Code for the information of ISO3166-2 supported.
GetCity Return the city name of the proxy.
GetIsp Return the ISP name of the proxy.
GetDomain Return the domain name of the proxy.
GetUsageType Return the usage type classification of the proxy. Please visit IP2Location for the list of usage types supported.
GetAsn Return the autonomous system number of the proxy.
GetAs Return the autonomous system name of the proxy.
GetLastSeen Return the number of days that the proxy was last seen.
GetThreat Return the threat type of the proxy.
GetProvider Return the provider of the proxy.

Usage

package main

import (
	"fmt"
	"strconv"
	"github.com/ip2location/ip2proxy-go/v4"
)

func main() {
	db, err := ip2proxy.OpenDB("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN")
	
	if err != nil {
		return
	}
	ip := "199.83.103.79"
	all, err := db.GetAll(ip)
	
	if err != nil {
		fmt.Print(err)
		return
	}
	
	fmt.Printf("ModuleVersion: %s\n", ip2proxy.ModuleVersion())
	fmt.Printf("PackageVersion: %s\n", db.PackageVersion())
	fmt.Printf("DatabaseVersion: %s\n", db.DatabaseVersion())
	
	fmt.Printf("IsProxy: %s\n", strconv.Itoa(int(all.IsProxy)));
	fmt.Printf("ProxyType: %s\n", all.ProxyType);
	fmt.Printf("CountryShort: %s\n", all.CountryShort);
	fmt.Printf("CountryLong: %s\n", all.CountryLong);
	fmt.Printf("Region: %s\n", all.Region);
	fmt.Printf("City: %s\n", all.City);
	fmt.Printf("Isp: %s\n", all.Isp);
	fmt.Printf("Domain: %s\n", all.Domain);
	fmt.Printf("UsageType: %s\n", all.UsageType);
	fmt.Printf("Asn: %s\n", all.Asn);
	fmt.Printf("As: %s\n", all.As);
	fmt.Printf("LastSeen: %s\n", all.LastSeen);
	fmt.Printf("Threat: %s\n", all.Threat);
	
	db.Close()
}

QUERY USING THE IP2PROXY PROXY DETECTION WEB SERVICE

Methods

Below are the methods supported in this class.

Method Name Description
OpenWS(apikey string, apipackage string, usessl bool) Expects 3 input parameters:
  1. IP2Proxy API Key.
  2. Package (PX1 - PX11)
  3. Use HTTPS or HTTP
LookUp(ipAddress string) Query IP address. This method returns a struct containing the proxy info.
  • CountryCode
  • CountryName
  • RegionName
  • CityName
  • ISP
  • Domain
  • UsageType
  • ASN
  • AS
  • LastSeen
  • Threat
  • ProxyType
  • IsProxy
  • Provider
    GetCredit() This method returns the web service credit balance in a struct.
    package main
    
    import (
    	"fmt"
    	"github.com/ip2location/ip2proxy-go/v3"
    )
    
    func main() {
    	apikey := "YOUR_API_KEY"
    	apipackage := "PX11"
    	usessl := true
    
    	ws, err := ip2proxy.OpenWS(apikey, apipackage, usessl)
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    	ip := "8.8.8.8"
    	res, err := ws.LookUp(ip)
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    
    	if res.Response != "OK" {
    		fmt.Printf("Error: %s\n", res.Response)
    	} else {
    		fmt.Printf("IsProxy: %s\n", res.IsProxy)
    		fmt.Printf("ProxyType: %s\n", res.ProxyType)
    		fmt.Printf("CountryCode: %s\n", res.CountryCode)
    		fmt.Printf("CountryName: %s\n", res.CountryName)
    		fmt.Printf("RegionName: %s\n", res.RegionName)
    		fmt.Printf("CityName: %s\n", res.CityName)
    		fmt.Printf("ISP: %s\n", res.ISP)
    		fmt.Printf("Domain: %s\n", res.Domain)
    		fmt.Printf("UsageType: %s\n", res.UsageType)
    		fmt.Printf("ASN: %s\n", res.ASN)
    		fmt.Printf("AS: %s\n", res.AS)
    		fmt.Printf("LastSeen: %s\n", res.LastSeen)
    		fmt.Printf("Threat: %s\n", res.Threat)
    		fmt.Printf("Provider: %s\n", res.Provider)
    	}
    
    	res2, err := ws.GetCredit()
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    	
    	fmt.Printf("Credit Balance: %s\n", res2.Response)
    }
    

    Documentation

    Overview

    Package ip2proxy allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range, search engine robots (SES) and residential (RES) by using the IP2Proxy database.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func ModuleVersion

    func ModuleVersion() string

    ModuleVersion returns the version of the component.

    Types

    type ByteDBReader

    type ByteDBReader struct {
    	*bytes.Reader
    }

    func (*ByteDBReader) Close

    func (bdr *ByteDBReader) Close() error

    type DB

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

    The DB struct is the main object used to query the IP2Proxy BIN file.

    func OpenDB

    func OpenDB(dbPath string) (*DB, error)

    OpenDB takes the path to the IP2Proxy BIN database file. It will read all the metadata required to be able to extract the embedded proxy data, and return the underlining DB object.

    func OpenDBWithBytes

    func OpenDBWithBytes(data []byte) (*DB, error)

    OpenDBFromBytes use a byte slice to open the IP2Proxy BIN database file. It will read all the metadata required to be able to extract the embedded geolocation data, and return the underlining DB object.

    func OpenDBWithReader

    func OpenDBWithReader(reader dbReader) (*DB, error)

    OpenDBWithReader takes a dbReader to the IP2Proxy BIN database file. It will read all the metadata required to be able to extract the embedded proxy data, and return the underlining DB object.

    func (*DB) Close

    func (d *DB) Close() error

    Close is used to close file descriptor.

    func (*DB) DatabaseVersion

    func (d *DB) DatabaseVersion() string

    DatabaseVersion returns the database version.

    func (*DB) GetAll

    func (d *DB) GetAll(ipAddress string) (IP2ProxyRecord, error)

    GetAll will return all proxy fields based on the queried IP address.

    func (*DB) GetAs

    func (d *DB) GetAs(ipAddress string) (string, error)

    GetAs will return the autonomous system name based on the queried IP address.

    func (*DB) GetAsn

    func (d *DB) GetAsn(ipAddress string) (string, error)

    GetAsn will return the autonomous system number based on the queried IP address.

    func (*DB) GetCity

    func (d *DB) GetCity(ipAddress string) (string, error)

    GetCity will return the city name based on the queried IP address.

    func (*DB) GetCountryLong

    func (d *DB) GetCountryLong(ipAddress string) (string, error)

    GetCountryLong will return the country name based on the queried IP address.

    func (*DB) GetCountryShort

    func (d *DB) GetCountryShort(ipAddress string) (string, error)

    GetCountryShort will return the ISO-3166 country code based on the queried IP address.

    func (*DB) GetDomain

    func (d *DB) GetDomain(ipAddress string) (string, error)

    GetDomain will return the domain name based on the queried IP address.

    func (*DB) GetIsp

    func (d *DB) GetIsp(ipAddress string) (string, error)

    GetIsp will return the Internet Service Provider name based on the queried IP address.

    func (*DB) GetLastSeen

    func (d *DB) GetLastSeen(ipAddress string) (string, error)

    GetLastSeen will return the number of days that the proxy was last seen based on the queried IP address.

    func (*DB) GetProvider

    func (d *DB) GetProvider(ipAddress string) (string, error)

    GetProvider will return the provider of the proxy.

    func (*DB) GetProxyType

    func (d *DB) GetProxyType(ipAddress string) (string, error)

    GetProxyType will return the proxy type based on the queried IP address.

    func (*DB) GetRegion

    func (d *DB) GetRegion(ipAddress string) (string, error)

    GetRegion will return the region name based on the queried IP address.

    func (*DB) GetThreat

    func (d *DB) GetThreat(ipAddress string) (string, error)

    GetThreat will return the threat type of the proxy.

    func (*DB) GetUsageType

    func (d *DB) GetUsageType(ipAddress string) (string, error)

    GetUsageType will return the usage type based on the queried IP address.

    func (*DB) IsProxy

    func (d *DB) IsProxy(ipAddress string) (int8, error)

    IsProxy checks whether the queried IP address was a proxy. Returned value: -1 (errors), 0 (not a proxy), 1 (a proxy), 2 (a data center IP address or search engine robot).

    func (*DB) PackageVersion

    func (d *DB) PackageVersion() string

    PackageVersion returns the database type.

    type IP2ProxyCreditResult

    type IP2ProxyCreditResult struct {
    	Response string `json:"response"`
    }

    The IP2ProxyCreditResult struct stores the credit balance for the IP2Proxy Web Service.

    type IP2ProxyRecord

    type IP2ProxyRecord struct {
    	CountryShort string
    	CountryLong  string
    	Region       string
    	City         string
    	Isp          string
    	ProxyType    string
    	Domain       string
    	UsageType    string
    	Asn          string
    	As           string
    	LastSeen     string
    	Threat       string
    	Provider     string
    	IsProxy      int8
    }

    The IP2ProxyRecord struct stores all of the available proxy info found in the IP2Proxy database.

    type IP2ProxyResult

    type IP2ProxyResult struct {
    	Response    string `json:"response"`
    	CountryCode string `json:"countryCode"`
    	CountryName string `json:"countryName"`
    	RegionName  string `json:"regionName"`
    	CityName    string `json:"cityName"`
    	ISP         string `json:"isp"`
    	Domain      string `json:"domain"`
    	UsageType   string `json:"usageType"`
    	ASN         string `json:"asn"`
    	AS          string `json:"as"`
    	LastSeen    string `json:"lastSeen"`
    	ProxyType   string `json:"proxyType"`
    	Threat      string `json:"threat"`
    	IsProxy     string `json:"isProxy"`
    	Provider    string `json:"provider"`
    }

    The IP2ProxyResult struct stores all of the available proxy info found in the IP2Proxy Web Service.

    type WS

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

    The WS struct is the main object used to query the IP2Proxy Web Service.

    func OpenWS

    func OpenWS(apikey string, apipackage string, usessl bool) (*WS, error)

    OpenWS initializes with the web service API key, API package and whether to use SSL

    func (*WS) GetCredit

    func (w *WS) GetCredit() (IP2ProxyCreditResult, error)

    GetCredit will return the web service credit balance.

    func (*WS) LookUp

    func (w *WS) LookUp(ipAddress string) (IP2ProxyResult, error)

    LookUp will return all proxy fields based on the queried IP address.

    Jump to

    Keyboard shortcuts

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