Skip to content

Commit 2f29726

Browse files
committed
Add IP2Proxy web service
1 parent 2a90e3e commit 2f29726

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

LICENSE.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 IP2Location.com
3+
Copyright (c) 2020 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Latest Stable Version](https://img.shields.io/packagist/v/ip2location/ip2proxy-cakephp.svg)](https://packagist.org/packages/ip2location/ip2proxy-cakephp)
33
[![Total Downloads](https://img.shields.io/packagist/dt/ip2location/ip2proxy-cakephp.svg?style=flat-square)](https://packagist.org/packages/ip2location/ip2proxy-cakephp)
44

5-
IP2Proxy CakePHP plugin enables the user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits. It lookup the proxy IP address from IP2Proxy BIN Data file. Developers can use the API to query all IP2Proxy BIN databases for applications written using CakePHP.
5+
IP2Proxy CakePHP plugin enables the user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exit nodes, search engine robots, data center ranges and residential proxies. It lookup the proxy IP address from IP2Proxy BIN Data file or web service. Developers can use the API to query all IP2Proxy BIN databases or web service for applications written using CakePHP.
66

77

88
## INSTALLATION
@@ -38,6 +38,15 @@ namespace App\Controller;
3838
use App\Controller\AppController;
3939
use IP2ProxyCakePHP\Controller\IP2ProxyCoresController;
4040
41+
// (required) Define IP2Proxy API key.
42+
define('IP2PROXY_API_KEY', 'your_api_key');
43+
44+
// (required) Define IP2Proxy Web service package of different granularity of return information.
45+
define('IP2PROXY_PACKAGE', 'PX1');
46+
47+
// (optional) Define to use https or http.
48+
define('IP2PROXY_USESSL', false);
49+
4150
/**
4251
* Tests Controller
4352
*/
@@ -52,8 +61,9 @@ class TestsController extends AppController
5261
public function index()
5362
{
5463
$IP2Proxy = new IP2ProxyCoresController();
55-
$record = $IP2Proxy->get('1.0.241.135');
5664
65+
$record = $IP2Proxy->get('1.0.241.135');
66+
echo 'Result from BIN Database:<br>';
5767
echo '<p><strong>IP Address: </strong>' . $record['ipAddress'] . '</p>';
5868
echo '<p><strong>IP Number: </strong>' . $record['ipNumber'] . '</p>';
5969
echo '<p><strong>IP Version: </strong>' . $record['ipVersion'] . '</p>';
@@ -64,19 +74,33 @@ class TestsController extends AppController
6474
echo '<p><strong>Proxy Type: </strong>' . $record['proxyType'] . '</p>';
6575
echo '<p><strong>Is Proxy: </strong>' . $record['isProxy'] . '</p>';
6676
echo '<p><strong>ISP: </strong>' . $record['isp'] . '</p>';
77+
echo '<p><strong>Domain: </strong>' . $record['domain'] . '</p>';
78+
echo '<p><strong>Usage Type: </strong>' . $record['usageType'] . '</p>';
79+
echo '<p><strong>ASN: </strong>' . $record['asn'] . '</p>';
80+
echo '<p><strong>AS: </strong>' . $record['as'] . '</p>';
81+
echo '<p><strong>Last Seen: </strong>' . $record['lastSeen'] . '</p>';
82+
echo '<p><strong>Threat: </strong>' . $record['threat'] . '</p>';
83+
84+
$record = $IP2Proxy->getWebService('1.0.241.135');
85+
echo 'Result from Web service:<br>';
86+
echo '<pre>';
87+
print_r ($record);
88+
echo '</pre>';
6789
}
6890
6991
}
7092
```
7193
5. Enter the URL <your domain>/Tests and run. You should see the information of **1.0.241.135** IP address.
7294

7395

74-
7596
## DEPENDENCIES (IP2PROXY BIN DATA FILE)
76-
This library requires IP2Proxy BIN data file to function. You may download the BIN data file at
97+
This library requires IP2Proxy BIN or IP2Proxy API key data file to function. You may download the BIN data file at
7798
* IP2Proxy LITE BIN Data (Free): https://lite.ip2location.com
7899
* IP2Proxy Commercial BIN Data (Comprehensive): https://www.ip2location.com/proxy-database
79100

101+
You can also sign up for [IP2Proxy Web Service](https://www.ip2location.com/web-service/ip2proxy) to get one free API key.
102+
103+
80104
## SUPPORT
81105
82106

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ip2location/ip2proxy-cakephp",
3-
"description": "Allow users to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.",
4-
"keywords": ["cakephp", "ip2proxy", "geolocation"],
3+
"description": "Allow users to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exit nodes, search engine robots, data center ranges and residential proxies.",
4+
"keywords": ["cakephp", "ip2proxy", "geolocation", "proxy"],
55
"homepage": "https://github.com/ip2location/ip2proxy-cakephp",
66
"license": "MIT",
77
"authors": [
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": ">=5.4.0",
1515
"cakephp/cakephp": ">=3.0",
16-
"ip2location/ip2proxy-php": "1.*"
16+
"ip2location/ip2proxy-php": ">=3.0"
1717
},
1818
"autoload": {
1919
"psr-4": {

src/Controller/IP2ProxyCoresController.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
<?php
22
namespace IP2ProxyCakePHP\Controller;
33

4+
// Web Service Settings
5+
if(!defined('IP2PROXY_API_KEY')) {
6+
define('IP2PROXY_API_KEY', 'demo');
7+
}
8+
9+
if(!defined('IP2PROXY_PACKAGE')) {
10+
define('IP2PROXY_PACKAGE', 'PX1');
11+
}
12+
13+
if(!defined('IP2PROXY_USESSL')) {
14+
define('IP2PROXY_USESSL', false);
15+
}
16+
417
/**
518
* IP2ProxyCores Controller
619
*/
@@ -14,14 +27,13 @@ class IP2ProxyCoresController
1427
*/
1528
public function index()
1629
{
17-
//
30+
//
1831
}
1932

2033
public function get($ip, $query = array())
2134
{
2235
$obj = new \IP2Proxy\Database();
23-
$obj->open(ROOT . DS . 'vendor' . DS . 'ip2location' . DS . 'ip2proxy-cakephp' . DS . 'src' . DS . 'data' . DS . 'IP2PROXY.BIN', \IP2Proxy\Database::FILE_IO);
24-
36+
$obj->open(ROOT . DS . 'vendor' . DS . 'ip2location' . DS . 'ip2proxy-cakephp' . DS . 'src' . DS . 'Data' . DS . 'IP2PROXY.BIN', \IP2Proxy\Database::FILE_IO);
2537

2638
try {
2739
$records = $obj->getAll($ip);
@@ -33,4 +45,17 @@ public function get($ip, $query = array())
3345
return $records;
3446
}
3547

48+
public function getWebService($ip)
49+
{
50+
$ws = new \IP2Proxy\WebService(IP2PROXY_API_KEY, IP2PROXY_PACKAGE, IP2PROXY_USESSL);
51+
52+
try {
53+
$records = $ws->lookup($ip);
54+
} catch (Exception $e) {
55+
return null;
56+
}
57+
58+
return $records;
59+
}
60+
3661
}

0 commit comments

Comments
 (0)