Skip to content

Commit a8a577b

Browse files
committed
Major restructure for better standards.
1 parent 3d14a98 commit a8a577b

File tree

11 files changed

+432
-330
lines changed

11 files changed

+432
-330
lines changed

README.md

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,13 @@ Below are the methods supported in this class.
1414

1515
### BIN Database Class
1616

17-
|Method Name|Description|
17+
| Function Name | Description |
1818
|---|---|
19-
|open|Open the IP2Proxy BIN data for lookup. Please see the **Usage** section of the 3 modes supported to load the BIN data file.|
20-
|close|Close and clean up the file pointer.|
21-
|getPackageVersion|Get the package version (1 to 10 for PX1 to PX10 respectively).|
22-
|getModuleVersion|Get the module version.|
23-
|getDatabaseVersion|Get the database version.|
24-
|isProxy|Check whether if an IP address was a proxy. Returned value:<ul><li>-1 : errors</li><li>0 : not a proxy</li><li>1 : a proxy</li><li>2 : a data center IP address</li></ul>|
25-
|getAll|Return the proxy information in array.|
26-
|getProxyType|Return the proxy type. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of proxy types supported|
27-
|getCountryShort|Return the ISO3166-1 country code (2-digits) of the proxy.|
28-
|getCountryLong|Return the ISO3166-1 country name of the proxy.|
29-
|getRegion|Return the ISO3166-2 region name of the proxy. Please visit <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 Subdivision Code</a> for the information of ISO3166-2 supported|
30-
|getCity|Return the city name of the proxy.|
31-
|getISP|Return the ISP name of the proxy.|
32-
|getDomain|Internet domain name associated with IP address range.|
33-
|getUsageType|Usage type classification of ISP or company. Refer to usage type reference below.|
34-
|getASN|Autonomous system number (ASN).|
35-
|getAS|Autonomous system (AS) name.|
36-
|getLastSeen|Proxy last seen in days.|
37-
|getThreat|Security threat reported.|
19+
|Constructor|Expect 2 input parameters:<ol><li>Full path of IP2Proxy BIN data file.</li><li>File Open Mode<ul><li> SHARED_MEMORY</li><li>MEMORY_CACHE</li><li>FILE_IO</li></ul></li></ol>For SHARED_MEMORY and MEMORY_CACHE, it will require your server to have sufficient memory to hold the BIN data, otherwise it will raise the errors during the object initialization.|
20+
|**string** getDatabaseVersion()|Return the database's compilation date as a string of the form 'YYYY-MM-DD',|
21+
|**string** getPackageVersion()|Return the database's type, 1 to 10 respectively for PX1 to PX10. Please visit https://www.ip2location.com/databases/ip2proxy for details.|
22+
|**string** getModuleVersion()|Return the version of module.|
23+
|**array** lookup($ip)|Return the IP information in array. Below is the information returned:<ul><li>ipNumber</li><li>ipVersion</li><li>ipAddress</li><li>countryCode</li><li>countryName</li><li>regionName</li><li>cityName</li><li>isp</li><li>domain</li><li>usageType</li><li>asn</li><li>as</li><li>lastSeen</li><li>threat</li><li>proxyType</li><li>isProxy</li></ul>You can visit [IP2Location](https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential) website for the description of each field. Note: although the above names are not exactly matched with the names given in this link, but they are self-described.|
3824

3925

4026

@@ -59,16 +45,15 @@ Open and read IP2Proxy binary database. There are 3 modes:
5945
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.
6046

6147
```php
62-
require 'class.IP2Proxy.php';
48+
require 'vendor/autoload.php';
6349

64-
$db = new \IP2Proxy\Database();
65-
$db->open('./samples/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.SAMPLE.BIN', \IP2Proxy\Database::FILE_IO);
50+
$db = new \IP2Proxy\Database('vendor/ip2location/ip2proxy-php/data/PX10.SAMPLE.BIN', \IP2PROXY\Database::FILE_IO);
6651
```
6752

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

70-
```
71-
$records = $db->getAll('1.0.241.135');
55+
```php
56+
$records = $db->lookup('1.0.0.8', \IP2PROXY\Database::ALL);
7257
```
7358

7459
Results are returned in array.
@@ -95,27 +80,9 @@ echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>';
9580
*/
9681
echo '<p><strong>Is Proxy: </strong>' . $records['isProxy'] . '</p>';
9782
echo '<p><strong>ISP: </strong>' . $records['isp'] . '</p>';
98-
99-
$domain = $db->getDomain('1.0.241.135');
100-
echo '<p><strong>Domain: </strong>' . $domain . '</p>';
101-
102-
$usageType = $db->getUsageType('1.0.241.135');
103-
echo '<p><strong>Usage Type: </strong>' . $usageType . '</p>';
104-
105-
$asn = $db->getASN('1.0.241.135');
106-
echo '<p><strong>ASN: </strong>' . $asn . '</p>';
107-
108-
$as = $db->getAS('1.0.241.135');
109-
echo '<p><strong>AS: </strong>' . $as . '</p>';
110-
111-
$lastSeen = $db->getLastSeen('1.0.241.135');
112-
echo '<p><strong>Last Seen: </strong>' . $lastSeen . '</p>';
113-
114-
$threat = $db->getThreat('1.0.241.135');
115-
echo '<p><strong>Threat: </strong>' . $threat . '</p>';
11683
```
11784

118-
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.
85+
11986

12087
### Web Service API
12188

@@ -124,7 +91,7 @@ To lookup by Web service, you will need to sign up for [IP2Proxy Web Service](ht
12491
Start your lookup by following codes:
12592

12693
```php
127-
require 'class.IP2Proxy.php';
94+
require 'vendor/autoload.php';
12895

12996
// Lookup by Web API
13097
$ws = new \IP2Proxy\WebService('YOUR_API_KEY', 'PX10', false);
@@ -152,6 +119,20 @@ if ($results !== false) {
152119

153120
# Reference
154121

122+
### Proxy Type
123+
124+
| Type | Description | Anonymity |
125+
| ---- | ------------------------------------------------------------ | --------- |
126+
| VPN | Anonymizing VPN services. These services offer users a publicly accessible VPN for the purpose of hiding their IP address. | High |
127+
| TOR | Tor Exit Nodes. The Tor Project is an open network used by those who wish to maintain anonymity. | High |
128+
| DCH | Hosting Provider, Data Center or Content Delivery Network. Since hosting providers and data centers can serve to provide anonymity, the Anonymous IP database flags IP addresses associated with them. | Low |
129+
| PUB | Public Proxies. These are services which make connection requests on a user's behalf. Proxy server software can be configured by the administrator to listen on some specified port. These differ from VPNs in that the proxies usually have limited functions compare to VPNs. | High |
130+
| WEB | Web Proxies. These are web services which make web requests on a user's behalf. These differ from VPNs or Public Proxies in that they are simple web-based proxies rather than operating at the IP address and other ports level. | High |
131+
| SES | Search Engine Robots. These are services which perform crawling or scraping to a website, such as, the search engine spider or bots engine. | Low |
132+
| RES | Residential proxies. These services offer users proxy connections through residential ISP with or without consents of peers to share their idle resources. Only available with PX10 | Medium |
133+
134+
135+
155136
### Usage Type
156137

157138
- (COM) Commercial

composer.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
"email": "[email protected]"
1212
}
1313
],
14+
"require-dev": {
15+
"phpunit/phpunit": "^9.5"
16+
},
1417
"require": {
15-
"php": ">=5.6",
16-
"ext-bcmath" : "*"
18+
"php": ">=7.2",
19+
"ext-bcmath": "*",
20+
"ext-curl": "*",
21+
"ext-gmp": "*",
22+
"ext-json": "*"
1723
},
1824
"autoload": {
19-
"classmap": [
20-
"class.IP2Proxy.php"
21-
]
25+
"psr-4": {
26+
"IP2Proxy\\": "src"
27+
}
2228
}
2329
}

data/PX10.SAMPLE.BIN

1 MB
Binary file not shown.

example.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

examples/example.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
// Lookup by local BIN database
6+
$db = new \IP2Proxy\Database('vendor/ip2location/ip2proxy-php/data/PX10.SAMPLE.BIN', \IP2PROXY\Database::FILE_IO);
7+
8+
echo 'Get All Fields' . PHP_EOL;
9+
$records = $db->lookup('1.0.0.8', \IP2PROXY\Database::ALL);
10+
print_r($records);
11+
12+
echo PHP_EOL . PHP_EOL;
13+
14+
echo 'Web Service' . PHP_EOL;
15+
16+
// Lookup by Web API
17+
$ws = new \IP2Proxy\WebService('demo', 'PX10', false);
18+
19+
$results = $ws->lookup('1.0.0.8');
20+
print_r($results);

phpunit.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit bootstrap="tests/bootstrap.php" colors="true">
2+
<testsuites>
3+
<testsuite name="IP2Proxy PHP SDK Testcase">
4+
<directory suffix="Test.php">./tests/</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>

0 commit comments

Comments
 (0)