Giter Club home page Giter Club logo

ip2proxy-php's Introduction

IP2Proxy PHP Module

Latest Stable Version Total Downloads

This module allows user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits. It lookup the proxy IP address from IP2Proxy BIN Data file. This data file can be downloaded at

Methods

Below are the methods supported in this class.

BIN Database Class

Method Name Description
open Open the IP2Proxy BIN data for lookup. Please see the Usage section of the 3 modes supported to load the BIN data file.
close Close and clean up the file pointer.
getPackageVersion Get the package version (1 to 4 for PX1 to PX4 respectively).
getModuleVersion Get the module version.
getDatabaseVersion 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
getAll Return the proxy information in 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 Internet domain name associated with IP address range.
getUsageType Usage type classification of ISP or company. Refer to usage type reference below.
getASN Autonomous system number (ASN).
getAS Autonomous system (AS) name.
getLastSeen Proxy last seen in days.

Web Service Class

Method Name Description
Constructor Expect 3 input parameters:
  1. IP2Proxy API Key.
  2. Package (PX1 - PX8)
  3. Use HTTPS or HTTP
lookup Return the proxy information in array.
  • countryCode
  • countryName
  • regionName
  • cityName
  • isp
  • domain
  • usageType
  • asn
  • as
  • lastSeen
  • proxyType
  • isProxy
getCredit Return remaining credit of the web service account.

Usage

BIN Database

Open and read IP2Proxy binary database. There are 3 modes:

  1. \IP2Proxy\Database::FILE_IO - File I/O reading. Slower look, but low resource consuming.
  2. \IP2Proxy\Database::MEMORY_CACHE - Caches database into memory for faster lookup. Required high memory.
  3. \IP2Proxy\Database::SHARED_MEMORY - Stores whole IP2Proxy database into system memory. Lookup is possible across all applications within the system. Extremely resources consuming. Do not use this mode if your system do not have enough memory.
require 'class.IP2Proxy.php';

$db = new \IP2Proxy\Database();
$db->open('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);

To start lookup result from database, use the following codes:

$records = $db->getAll('1.0.241.135');

Results are returned in array.

echo '<p><strong>IP Address: </strong>' . $records['ipAddress'] . '</p>';
echo '<p><strong>IP Number: </strong>' . $records['ipNumber'] . '</p>';
echo '<p><strong>IP Version: </strong>' . $records['ipVersion'] . '</p>';
echo '<p><strong>Country Code: </strong>' . $records['countryCode'] . '</p>';
echo '<p><strong>Country: </strong>' . $records['countryName'] . '</p>';
echo '<p><strong>State: </strong>' . $records['regionName'] . '</p>';
echo '<p><strong>City: </strong>' . $records['cityName'] . '</p>';

/*
  Type of proxy: VPN, TOR, DCH, PUB, WEB
*/
echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>';

/*
  Returns -1 on errors
  Returns 0 is not proxy
  Return 1 if proxy
  Return 2 if it's data center IP
*/
echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>';
echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>';

$domain = $db->getDomain('1.0.241.135');
echo '<p><strong>Domain: </strong>' . $domain . '</p>';

$usageType = $db->getUsageType('1.0.241.135');
echo '<p><strong>Usage Type: </strong>' . $usageType . '</p>';

$asn = $db->getASN('1.0.241.135');
echo '<p><strong>ASN: </strong>' . $asn . '</p>';

$as = $db->getAS('1.0.241.135');
echo '<p><strong>AS: </strong>' . $as . '</p>';

$lastSeen = $db->getLastSeen('1.0.241.135');
echo '<p><strong>Last Seen: </strong>' . $lastSeen . '</p>';

Note: if you are getting error such as Call to undefined function IP2Proxy\gmp_import(), you probably did not have the module to install or enable in php.ini. You can check your php.ini to make sure that the module has been enabled.

Web Service API

To lookup by Web service, you will need to sign up for IP2Proxy Web Service to get a API key.

Start your lookup by following codes:

require 'class.IP2Proxy.php';

// Lookup by Web API
$ws = new \IP2Proxy\WebService('YOUR_API_KEY',  'PX8', false);

$results = $ws->lookup('1.0.241.135');

if ($results !== false) {
    echo '<p><strong>Country Code: </strong>' . $results['countryCode'] . '</p>';
    echo '<p><strong>Country Name: </strong>' . $results['countryName'] . '</p>';
    echo '<p><strong>Region: </strong>' . $results['regionName'] . '</p>';
    echo '<p><strong>City: </strong>' . $results['cityName'] . '</p>';
    echo '<p><strong>ISP: </strong>' . $results['isp'] . '</p>';
    echo '<p><strong>Domain: </strong>' . $results['domain'] . '</p>';
    echo '<p><strong>Usage Type: </strong>' . $results['usageType'] . '</p>';
    echo '<p><strong>ASN: </strong>' . $results['asn'] . '</p>';
    echo '<p><strong>AS: </strong>' . $results['as'] . '</p>';
    echo '<p><strong>Last Seen: </strong>' . $results['lastSeen'] . ' Day(s)</p>';
    echo '<p><strong>Proxy Type: </strong>' . $results['proxyType'] . '</p>';
    echo '<p><strong>Is Proxy: </strong>' . $results['isProxy'] . '</p>';
}

Reference

Usage Type

  • (COM) Commercial
  • (ORG) Organization
  • (GOV) Government
  • (MIL) Military
  • (EDU) University/College/School
  • (LIB) Library
  • (CDN) Content Delivery Network
  • (ISP) Fixed Line ISP
  • (MOB) Mobile ISP
  • (DCH) Data Center/Web Hosting/Transit
  • (SES) Search Engine Spider
  • (RSV) Reserved

ip2proxy-php's People

Contributors

ip2location avatar chrislim2888 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.