Skip to content

Commit 97ef394

Browse files
committed
Initial commit.
1 parent 5aab97d commit 97ef394

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
### IP2Proxy PHP Module
2+
3+
This is the PHP module to lookup IP2Proxy databases from https://www.ip2location.com/proxy-database
4+
5+
**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.
6+
7+
8+
9+
#### Usage
10+
11+
Open and read IP2Proxy binary database. There are 3 modes:
12+
13+
1. **\IP2Proxy\Database::FILE_IO** - File I/O reading. Slower look, but low resource consuming.
14+
2. **\IP2Proxy\Database::MEMORY_CACHE** - Caches database into memory for faster lookup. Required high memory.
15+
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.
16+
17+
```
18+
require 'class.IP2Proxy.php';
19+
20+
$db = new \IP2Proxy\Database('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
21+
```
22+
23+
To start lookup result from database, use the following codes:
24+
25+
```
26+
$records = $db->lookup('1.0.241.135', \IP2Proxy\Database::ALL);
27+
```
28+
29+
Results are returned in array.
30+
31+
```
32+
echo '<p><strong>IP Address: </strong>' . $records['ipAddress'] . '</p>';
33+
echo '<p><strong>IP Number: </strong>' . $records['ipNumber'] . '</p>';
34+
echo '<p><strong>IP Version: </strong>' . $records['ipVersion'] . '</p>';
35+
echo '<p><strong>Country Code: </strong>' . $records['countryCode'] . '</p>';
36+
echo '<p><strong>Country: </strong>' . $records['countryName'] . '</p>';
37+
echo '<p><strong>State: </strong>' . $records['regionName'] . '</p>';
38+
echo '<p><strong>City: </strong>' . $records['cityName'] . '</p>';
39+
40+
/*
41+
Type of proxy: VPN, TOR, DCH, PUB, WEB
42+
*/
43+
echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>';
44+
45+
/*
46+
Returns -1 on errors
47+
Returns 0 is not proxy
48+
Return 1 if proxy
49+
Return 2 if it's data center IP
50+
*/
51+
echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>';
52+
echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>';
53+
```
54+
55+
56+

class.IP2Proxy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class Database {
271271
/**
272272
* Column offset mapping
273273
*
274-
* Each entry contains an array mapping databse version (0--23) to offset within a record.
274+
* Each entry contains an array mapping databse version (0-3) to offset within a record.
275275
* A value of 0 means the column is not present in the given database version.
276276
*
277277
* @access private
@@ -386,7 +386,7 @@ class Database {
386386
private $date;
387387

388388
/**
389-
* Database's type (0--23)
389+
* Database's type (0-3)
390390
*
391391
* @access private
392392
* @var int

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "ip2location/ip2proxy-php",
3+
"type": "library",
4+
"description": "A PHP module to lookup for Proxy/VPN IP address from IP2Proxy database.",
5+
"keywords": ["geolocation", "detect vpn", "ip to vpn"],
6+
"homepage": "http://www.ip2location.com/",
7+
"license": "GPL",
8+
"authors": [
9+
{
10+
"name": "IP2Location",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"require": {
15+
"php": ">=5.3"
16+
},
17+
"autoload": {
18+
"classmap": [
19+
"class.IP2Proxy.php"
20+
]
21+
}
22+
}

example.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
require 'class.IP2Proxy.php';
3+
4+
$db = new \IP2Proxy\Database('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
5+
$records = $db->lookup('1.0.241.135', \IP2Proxy\Database::ALL);
6+
7+
echo '<p><strong>IP Address: </strong>' . $records['ipAddress'] . '</p>';
8+
echo '<p><strong>IP Number: </strong>' . $records['ipNumber'] . '</p>';
9+
echo '<p><strong>IP Version: </strong>' . $records['ipVersion'] . '</p>';
10+
echo '<p><strong>Country Code: </strong>' . $records['countryCode'] . '</p>';
11+
echo '<p><strong>Country: </strong>' . $records['countryName'] . '</p>';
12+
echo '<p><strong>State: </strong>' . $records['regionName'] . '</p>';
13+
echo '<p><strong>City: </strong>' . $records['cityName'] . '</p>';
14+
echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>';
15+
echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>';
16+
echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>';
Binary file not shown.

0 commit comments

Comments
 (0)