Skip to content

Commit

Permalink
Added supports for PX8.
Browse files Browse the repository at this point in the history
  • Loading branch information
seikan committed Jun 10, 2019
1 parent 3347c2a commit 16be841
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 88 deletions.
108 changes: 41 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To begin, an API key is required for this module to function. Find further infor
## Installation
Add the following to your composer.json file:

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

## Usage

```
```php
<?php

class IP2ProxyAPI
{
public $response;
public $ipAddress;
public $countryCode;
public $countryName;
public $regionName;
public $cityName;
public $isp;
public $proxyType;
public $isProxy;
protected $apiKey;
protected $useSSL;
public function __construct($apiKey = '', $useSSL = false)
{
$this->apiKey = $apiKey;
$this->useSSL = $useSSL;
}
public function query($ip)
{
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return false;
}
$response = $this->get('http' . (($this->useSSL) ? 's' : '') . '://api.ip2proxy.com/?' . http_build_query([
'key' => $this->apiKey,
'ip' => $ip,
'package' => 'PX4',
'format' => 'json',
]));
if (($json = json_decode($response)) === null) {
return false;
}
$this->response = (string) $json->response;
$this->countryCode = (string) $json->countryCode;
$this->countryName = (string) $json->countryName;
$this->regionName = (string) $json->regionName;
$this->cityName = (string) $json->cityName;
$this->isp = (string) $json->isp;
$this->proxyType = (string) $json->proxyType;
$this->isProxy = (string) $json->isProxy;
return true;
}
private function get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-1.0.0');
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$response = curl_exec($ch);
return $response;
}
require 'class.IP2ProxyAPI.php';

$api = new IP2ProxyAPI('YOUR_API_KEY');

if ($api->query('1.2.3.4')) {
echo '<strong>Country Code</strong>: ' . $api->countryCode . '<br>';
echo '<strong>Country Name</strong>: ' . $api->countryName . '<br>';
echo '<strong>Region</strong>: ' . $api->regionName . '<br>';
echo '<strong>City</strong>: ' . $api->cityName . '<br>';
echo '<strong>ISP</strong>: ' . $api->isp . '<br>';
echo '<strong>Domain</strong>: ' . $api->domain . '<br>';
echo '<strong>Usage Type</strong>: ' . $api->usageType . '<br>';
echo '<strong>ASN</strong>: ' . $api->asn . '<br>';
echo '<strong>AS</strong>: ' . $api->as . '<br>';
echo '<strong>Last Seen</strong>: ' . $api->lastSeen . '<br>';
echo '<strong>Proxy Type</strong>: ' . $api->proxyType . '<br>';
echo '<strong>Is Proxy</strong>: ' . $api->isProxy . '<br>';
}
?>
```


Expand All @@ -103,3 +55,25 @@ class IP2ProxyAPI
| isp | The service provider name. |
| 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 |
| proxyType | The type of proxy service. |
| domain | Internet domain name associated with IP address range. |
| usageType | Usage type classification of ISP or company. Refer **Usage Type** section. |
| asn | Autonomous system number (ASN). |
| as | Autonomous system (AS) name. |
| lastSeen | Proxy last seen in days. |



##### 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
16 changes: 13 additions & 3 deletions class.IP2ProxyAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class IP2ProxyAPI
public $regionName;
public $cityName;
public $isp;
public $domain;
public $usageType;
public $asn;
public $as;
public $lastSeen;
public $proxyType;
public $isProxy;

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

public function query($ip)
{
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
return false;
}

$response = $this->get('http' . (($this->useSSL) ? 's' : '') . '://api.ip2proxy.com/?' . http_build_query([
'key' => $this->apiKey,
'ip' => $ip,
'package' => 'PX4',
'package' => 'PX8',
'format' => 'json',
]));

Expand All @@ -44,6 +49,11 @@ public function query($ip)
$this->regionName = (string) $json->regionName;
$this->cityName = (string) $json->cityName;
$this->isp = (string) $json->isp;
$this->domain = (string) $json->domain;
$this->usageType = (string) $json->usageType;
$this->asn = (string) $json->asn;
$this->as = (string) $json->as;
$this->lastSeen = (string) $json->lastSeen;
$this->proxyType = (string) $json->proxyType;
$this->isProxy = (string) $json->isProxy;

Expand All @@ -58,7 +68,7 @@ private function get($url)
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-1.0.0');
curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-2.0.0');
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$response = curl_exec($ch);

Expand Down
33 changes: 15 additions & 18 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?php

require_once 'class.IP2ProxyAPI.php';
require 'class.IP2ProxyAPI.php';

$apiKey = 'YOUR_API_KEY';
$ip = '8.8.8.8';
$api = new IP2ProxyAPI('YOUR_API_KEY');

$ipx = new IP2ProxyAPI($apiKey, false);

if (!$ipx->query($ip)) {
die('ERROR');
if ($api->query('1.2.3.4')) {
echo '<strong>Country Code</strong>: ' . $api->countryCode . '<br>';
echo '<strong>Country Name</strong>: ' . $api->countryName . '<br>';
echo '<strong>Region</strong>: ' . $api->regionName . '<br>';
echo '<strong>City</strong>: ' . $api->cityName . '<br>';
echo '<strong>ISP</strong>: ' . $api->isp . '<br>';
echo '<strong>Domain</strong>: ' . $api->domain . '<br>';
echo '<strong>Usage Type</strong>: ' . $api->usageType . '<br>';
echo '<strong>ASN</strong>: ' . $api->asn . '<br>';
echo '<strong>AS</strong>: ' . $api->as . '<br>';
echo '<strong>Last Seen</strong>: ' . $api->lastSeen . '<br>';
echo '<strong>Proxy Type</strong>: ' . $api->proxyType . '<br>';
echo '<strong>Is Proxy</strong>: ' . $api->isProxy . '<br>';
}

echo '<pre>';
echo 'Response : ' . $ipx->response . "\n";
echo 'Country Code : ' . $ipx->countryCode . "\n";
echo 'Country Name : ' . $ipx->countryName . "\n";
echo 'Region Name : ' . $ipx->regionName . "\n";
echo 'City Name : ' . $ipx->cityName . "\n";
echo 'ISP : ' . $ipx->isp . "\n";
echo 'Proxy Type : ' . $ipx->proxyType . "\n";
echo 'Is Proxy : ' . $ipx->isProxy . "\n";
echo '</pre>';

0 comments on commit 16be841

Please sign in to comment.