Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Nov 29, 2016
1 parent 5aab97d commit 97ef394
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
### IP2Proxy PHP Module

This is the PHP module to lookup IP2Proxy databases from https://www.ip2location.com/proxy-database

**IP2Proxy Database** contains IP addresses which are used as VPN anonymizer, open proxies, web proxies and Tor exits. The database includes records for all public IPv4 addresses.



#### Usage

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('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
```

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

```
$records = $db->lookup('1.0.241.135', \IP2Proxy\Database::ALL);
```

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>';
```



4 changes: 2 additions & 2 deletions class.IP2Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class Database {
/**
* Column offset mapping
*
* Each entry contains an array mapping databse version (0--23) to offset within a record.
* Each entry contains an array mapping databse version (0-3) to offset within a record.
* A value of 0 means the column is not present in the given database version.
*
* @access private
Expand Down Expand Up @@ -386,7 +386,7 @@ class Database {
private $date;

/**
* Database's type (0--23)
* Database's type (0-3)
*
* @access private
* @var int
Expand Down
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ip2location/ip2proxy-php",
"type": "library",
"description": "A PHP module to lookup for Proxy/VPN IP address from IP2Proxy database.",
"keywords": ["geolocation", "detect vpn", "ip to vpn"],
"homepage": "http://www.ip2location.com/",
"license": "GPL",
"authors": [
{
"name": "IP2Location",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3"
},
"autoload": {
"classmap": [
"class.IP2Proxy.php"
]
}
}
16 changes: 16 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require 'class.IP2Proxy.php';

$db = new \IP2Proxy\Database('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
$records = $db->lookup('1.0.241.135', \IP2Proxy\Database::ALL);

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>';
echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>';
echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>';
echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>';
Binary file not shown.

0 comments on commit 97ef394

Please sign in to comment.