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

github.com/ip2location/ip2proxy-go/v3

IP2Proxy Go package allows users to query an IP address to determine if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.

by IP2Location

v3.3.2 (see all)License:MIT
go get github.com/ip2location/ip2proxy-go/v3
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 NameDescription
OpenDBOpen the IP2Proxy BIN data for lookup.
CloseClose and clean up the file pointer.
PackageVersionGet the package version (1 to 11 for PX1 to PX11 respectively).
ModuleVersionGet the module version.
DatabaseVersionGet the database version.
IsProxyCheck 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
GetAllReturn the proxy information in an array.
GetProxyTypeReturn the proxy type. Please visit IP2Location for the list of proxy types supported.
GetCountryShortReturn the ISO3166-1 country code (2-digits) of the proxy.
GetCountryLongReturn the ISO3166-1 country name of the proxy.
GetRegionReturn the ISO3166-2 region name of the proxy. Please visit ISO3166-2 Subdivision Code for the information of ISO3166-2 supported.
GetCityReturn the city name of the proxy.
GetIspReturn the ISP name of the proxy.
GetDomainReturn the domain name of the proxy.
GetUsageTypeReturn the usage type classification of the proxy. Please visit IP2Location for the list of usage types supported.
GetAsnReturn the autonomous system number of the proxy.
GetAsReturn the autonomous system name of the proxy.
GetLastSeenReturn the number of days that the proxy was last seen.
GetThreatReturn the threat type of the proxy.
GetProviderReturn 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 NameDescription
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)
    }
    

    GitHub Stars

    12

    LAST COMMIT

    7mos ago

    MAINTAINERS

    0

    CONTRIBUTORS

    2

    OPEN ISSUES

    0

    OPEN PRs

    0
    VersionTagPublished
    v3.3.2
    8mos ago
    No alternatives found
    No tutorials found
    Add a tutorial