Skip to content

Commit 16be841

Browse files
committed
Added supports for PX8.
1 parent 3347c2a commit 16be841

File tree

3 files changed

+69
-88
lines changed

3 files changed

+69
-88
lines changed

README.md

Lines changed: 41 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To begin, an API key is required for this module to function. Find further infor
99
## Installation
1010
Add the following to your composer.json file:
1111

12-
```
12+
```json
1313
{
1414
"require": {
1515
"ip2location/ip2proxy-php-api": "1.*"
@@ -19,75 +19,27 @@ Add the following to your composer.json file:
1919

2020
## Usage
2121

22-
```
22+
```php
2323
<?php
2424

25-
class IP2ProxyAPI
26-
{
27-
public $response;
28-
public $ipAddress;
29-
public $countryCode;
30-
public $countryName;
31-
public $regionName;
32-
public $cityName;
33-
public $isp;
34-
public $proxyType;
35-
public $isProxy;
36-
37-
protected $apiKey;
38-
protected $useSSL;
39-
40-
public function __construct($apiKey = '', $useSSL = false)
41-
{
42-
$this->apiKey = $apiKey;
43-
$this->useSSL = $useSSL;
44-
}
45-
46-
public function query($ip)
47-
{
48-
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
49-
return false;
50-
}
51-
52-
$response = $this->get('http' . (($this->useSSL) ? 's' : '') . '://api.ip2proxy.com/?' . http_build_query([
53-
'key' => $this->apiKey,
54-
'ip' => $ip,
55-
'package' => 'PX4',
56-
'format' => 'json',
57-
]));
58-
59-
if (($json = json_decode($response)) === null) {
60-
return false;
61-
}
62-
63-
$this->response = (string) $json->response;
64-
$this->countryCode = (string) $json->countryCode;
65-
$this->countryName = (string) $json->countryName;
66-
$this->regionName = (string) $json->regionName;
67-
$this->cityName = (string) $json->cityName;
68-
$this->isp = (string) $json->isp;
69-
$this->proxyType = (string) $json->proxyType;
70-
$this->isProxy = (string) $json->isProxy;
71-
72-
return true;
73-
}
74-
75-
private function get($url)
76-
{
77-
$ch = curl_init();
78-
79-
curl_setopt($ch, CURLOPT_URL, $url);
80-
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
81-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
82-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
83-
curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-1.0.0');
84-
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
85-
$response = curl_exec($ch);
86-
87-
return $response;
88-
}
25+
require 'class.IP2ProxyAPI.php';
26+
27+
$api = new IP2ProxyAPI('YOUR_API_KEY');
28+
29+
if ($api->query('1.2.3.4')) {
30+
echo '<strong>Country Code</strong>: ' . $api->countryCode . '<br>';
31+
echo '<strong>Country Name</strong>: ' . $api->countryName . '<br>';
32+
echo '<strong>Region</strong>: ' . $api->regionName . '<br>';
33+
echo '<strong>City</strong>: ' . $api->cityName . '<br>';
34+
echo '<strong>ISP</strong>: ' . $api->isp . '<br>';
35+
echo '<strong>Domain</strong>: ' . $api->domain . '<br>';
36+
echo '<strong>Usage Type</strong>: ' . $api->usageType . '<br>';
37+
echo '<strong>ASN</strong>: ' . $api->asn . '<br>';
38+
echo '<strong>AS</strong>: ' . $api->as . '<br>';
39+
echo '<strong>Last Seen</strong>: ' . $api->lastSeen . '<br>';
40+
echo '<strong>Proxy Type</strong>: ' . $api->proxyType . '<br>';
41+
echo '<strong>Is Proxy</strong>: ' . $api->isProxy . '<br>';
8942
}
90-
?>
9143
```
9244

9345

@@ -103,3 +55,25 @@ class IP2ProxyAPI
10355
| isp | The service provider name. |
10456
| isProxy | YES if the IP is a Proxy. NO if the IP is not a proxy. DCH if the IP belongs to Hosting Provider, Data Center or Content Delivery Network. Note: DCH is only available for PX2, PX3 and PX4 query |
10557
| proxyType | The type of proxy service. |
58+
| domain | Internet domain name associated with IP address range. |
59+
| usageType | Usage type classification of ISP or company. Refer **Usage Type** section. |
60+
| asn | Autonomous system number (ASN). |
61+
| as | Autonomous system (AS) name. |
62+
| lastSeen | Proxy last seen in days. |
63+
64+
65+
66+
##### Usage Type
67+
68+
- (COM) Commercial
69+
- (ORG) Organization
70+
- (GOV) Government
71+
- (MIL) Military
72+
- (EDU) University/College/School
73+
- (LIB) Library
74+
- (CDN) Content Delivery Network
75+
- (ISP) Fixed Line ISP
76+
- (MOB) Mobile ISP
77+
- (DCH) Data Center/Web Hosting/Transit
78+
- (SES) Search Engine Spider
79+
- (RSV) Reserved

class.IP2ProxyAPI.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class IP2ProxyAPI
99
public $regionName;
1010
public $cityName;
1111
public $isp;
12+
public $domain;
13+
public $usageType;
14+
public $asn;
15+
public $as;
16+
public $lastSeen;
1217
public $proxyType;
1318
public $isProxy;
1419

@@ -23,14 +28,14 @@ public function __construct($apiKey = '', $useSSL = false)
2328

2429
public function query($ip)
2530
{
26-
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
31+
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
2732
return false;
2833
}
2934

3035
$response = $this->get('http' . (($this->useSSL) ? 's' : '') . '://api.ip2proxy.com/?' . http_build_query([
3136
'key' => $this->apiKey,
3237
'ip' => $ip,
33-
'package' => 'PX4',
38+
'package' => 'PX8',
3439
'format' => 'json',
3540
]));
3641

@@ -44,6 +49,11 @@ public function query($ip)
4449
$this->regionName = (string) $json->regionName;
4550
$this->cityName = (string) $json->cityName;
4651
$this->isp = (string) $json->isp;
52+
$this->domain = (string) $json->domain;
53+
$this->usageType = (string) $json->usageType;
54+
$this->asn = (string) $json->asn;
55+
$this->as = (string) $json->as;
56+
$this->lastSeen = (string) $json->lastSeen;
4757
$this->proxyType = (string) $json->proxyType;
4858
$this->isProxy = (string) $json->isProxy;
4959

@@ -58,7 +68,7 @@ private function get($url)
5868
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
5969
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
6070
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
61-
curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-1.0.0');
71+
curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-2.0.0');
6272
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
6373
$response = curl_exec($ch);
6474

example.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<?php
22

3-
require_once 'class.IP2ProxyAPI.php';
3+
require 'class.IP2ProxyAPI.php';
44

5-
$apiKey = 'YOUR_API_KEY';
6-
$ip = '8.8.8.8';
5+
$api = new IP2ProxyAPI('YOUR_API_KEY');
76

8-
$ipx = new IP2ProxyAPI($apiKey, false);
9-
10-
if (!$ipx->query($ip)) {
11-
die('ERROR');
7+
if ($api->query('1.2.3.4')) {
8+
echo '<strong>Country Code</strong>: ' . $api->countryCode . '<br>';
9+
echo '<strong>Country Name</strong>: ' . $api->countryName . '<br>';
10+
echo '<strong>Region</strong>: ' . $api->regionName . '<br>';
11+
echo '<strong>City</strong>: ' . $api->cityName . '<br>';
12+
echo '<strong>ISP</strong>: ' . $api->isp . '<br>';
13+
echo '<strong>Domain</strong>: ' . $api->domain . '<br>';
14+
echo '<strong>Usage Type</strong>: ' . $api->usageType . '<br>';
15+
echo '<strong>ASN</strong>: ' . $api->asn . '<br>';
16+
echo '<strong>AS</strong>: ' . $api->as . '<br>';
17+
echo '<strong>Last Seen</strong>: ' . $api->lastSeen . '<br>';
18+
echo '<strong>Proxy Type</strong>: ' . $api->proxyType . '<br>';
19+
echo '<strong>Is Proxy</strong>: ' . $api->isProxy . '<br>';
1220
}
13-
14-
echo '<pre>';
15-
echo 'Response : ' . $ipx->response . "\n";
16-
echo 'Country Code : ' . $ipx->countryCode . "\n";
17-
echo 'Country Name : ' . $ipx->countryName . "\n";
18-
echo 'Region Name : ' . $ipx->regionName . "\n";
19-
echo 'City Name : ' . $ipx->cityName . "\n";
20-
echo 'ISP : ' . $ipx->isp . "\n";
21-
echo 'Proxy Type : ' . $ipx->proxyType . "\n";
22-
echo 'Is Proxy : ' . $ipx->isProxy . "\n";
23-
echo '</pre>';

0 commit comments

Comments
 (0)