ip2proxy

package module
v3.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: MIT Imports: 14 Imported by: 2

README

Go Report Card

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

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"
	"github.com/ip2location/ip2proxy-go"
)

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", 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"])
	fmt.Printf("Provider: %s\n", all["Provider"])
	
	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"
    )
    
    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 Close deprecated

    func Close() int8

    Close will close the file handle to the BIN file and reset.

    Deprecated: No longer being updated.

    func DatabaseVersion deprecated

    func DatabaseVersion() string

    DatabaseVersion returns the database version.

    Deprecated: No longer being updated.

    func GetAll deprecated

    func GetAll(ipAddress string) map[string]string

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

    Deprecated: No longer being updated.

    func GetAs deprecated

    func GetAs(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetAsn deprecated

    func GetAsn(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetCity deprecated

    func GetCity(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetCountryLong deprecated

    func GetCountryLong(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetCountryShort deprecated

    func GetCountryShort(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetDomain deprecated

    func GetDomain(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetIsp deprecated

    func GetIsp(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetLastSeen deprecated

    func GetLastSeen(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetProxyType deprecated

    func GetProxyType(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetRegion deprecated

    func GetRegion(ipAddress string) string

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

    Deprecated: No longer being updated.

    func GetUsageType deprecated

    func GetUsageType(ipAddress string) string

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

    Deprecated: No longer being updated.

    func IsProxy deprecated

    func IsProxy(ipAddress string) int8

    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).

    Deprecated: No longer being updated.

    func ModuleVersion

    func ModuleVersion() string

    ModuleVersion returns the version of the component.

    func Open deprecated

    func Open(dbPath string) int8

    Open 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.

    Deprecated: No longer being updated.

    func PackageVersion deprecated

    func PackageVersion() string

    PackageVersion returns the database type.

    Deprecated: No longer being updated.

    Types

    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 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) (map[string]string, 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 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