Skip to content

Commit 5570078

Browse files
committed
First release
0 parents  commit 5570078

9 files changed

+247
-0
lines changed

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# IP2Proxy Laravel Extension
2+
3+
IP2Proxy Laravel extension enables the user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.
4+
5+
6+
## INSTALLATION
7+
8+
1. Run the command: `composer require ip2location/ip2proxy-laravel` to download the package into the Laravel platform.
9+
2. Edit `config/app.php` and add the below line in 'providers' section:
10+
`Ip2location\IP2ProxyLaravel\IP2ProxyLaravelServiceProvider::class,`
11+
3. Then publish the config file by:
12+
`php artisan vendor:publish --provider=Ip2location\IP2ProxyLaravel\IP2ProxyLaravelServiceProvider --force`
13+
4. Download IP2Proxy BIN database
14+
- IP2Proxy free LITE database at http://lite.ip2location.com
15+
- IP2Proxy commercial database at http://www.ip2location.com/proxy-database
16+
5. Create a folder named as `ip2proxy` in the `database` directory.
17+
6. Unzip and copy the BIN file into `database/ip2proxy/` folder.
18+
7. Rename the BIN file to IP2PROXY.BIN.
19+
20+
21+
## USAGE
22+
23+
In this tutorial, we will show you on how to create a **TestController** to display the IP information.
24+
25+
1. Create a **TestController** in Laravel using the below command line
26+
```
27+
php artisan make:controller TestController
28+
```
29+
2. Open the **app/Http/Controllers/TestController.php** in any text editor.
30+
3. Add the below lines into the controller file.
31+
```
32+
<?php
33+
34+
namespace App\Http\Controllers;
35+
36+
use Illuminate\Http\Request;
37+
use IP2ProxyLaravel; //use IP2ProxyLaravel class
38+
39+
class TestController extends Controller
40+
{
41+
//Create a lookup function for display
42+
public function lookup(){
43+
//Try query the geolocation information of 1.2.3.4 IP address
44+
$record = IP2ProxyLaravel::get('1.2.3.4');
45+
46+
echo '<p><strong>IP Address: </strong>' . $record['ipAddress'] . '</p>';
47+
echo '<p><strong>IP Number: </strong>' . $record['ipNumber'] . '</p>';
48+
echo '<p><strong>IP Version: </strong>' . $record['ipVersion'] . '</p>';
49+
echo '<p><strong>Country Code: </strong>' . $record['countryCode'] . '</p>';
50+
echo '<p><strong>Country: </strong>' . $record['countryName'] . '</p>';
51+
echo '<p><strong>State: </strong>' . $record['regionName'] . '</p>';
52+
echo '<p><strong>City: </strong>' . $record['cityName'] . '</p>';
53+
echo '<p><strong>Proxy Type: </strong>' . $record['proxyType'] . '</p>';
54+
echo '<p><strong>Is Proxy: </strong>' . $record['isProxy'] . '</p>';
55+
echo '<p><strong>ISP: </strong>' . $record['isp'] . '</p>';
56+
}
57+
}
58+
```
59+
4. Add the following line into the *routes/web.php* file.
60+
```
61+
Route::get('test', 'TestController@lookup');
62+
```
63+
5. Enter the URL <your domain>/public/test and run. You should see the information of **1.2.3.4** IP address.
64+
65+
## DEPENDENCIES (IP2PROXY BIN DATA FILE)
66+
67+
This library requires IP2Proxy BIN data file to function. You may download the BIN data file at
68+
* IP2Proxy LITE BIN Data (Free): http://lite.ip2location.com
69+
* IP2Proxy Commercial BIN Data (Comprehensive): http://www.ip2location.com/proxy-database
70+
71+
72+
## SUPPORT
73+
74+
75+
76+
Website: http://www.ip2location.com

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "ip2location/ip2proxy-laravel",
3+
"description": "Allows user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.",
4+
"license": "MIT",
5+
"keywords": [
6+
"laravel",
7+
"laravel 5",
8+
"IP2Proxy",
9+
"proxy"
10+
],
11+
"authors": [
12+
{
13+
"name": "IP2Location",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"minimum-stability": "stable",
18+
"require": {
19+
"php": ">=5.4",
20+
"ip2location/ip2proxy-php": "1.*"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Ip2location\\IP2ProxyLaravel\\": "src/"
25+
}
26+
}
27+
}

license.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 IP2Location.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
bootstrap="../../../bootstrap/autoload.php"
12+
>
13+
<testsuites>
14+
<testsuite name="IP2ProxyLaravel Package Test Suite">
15+
<directory>./tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

src/Config/ip2proxylaravel.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
return[
3+
4+
'ip2proxy' => [
5+
'local' => [
6+
'path' => database_path('ip2proxy/IP2PROXY.BIN'),
7+
],
8+
],
9+
10+
];

src/Facade/IP2ProxyLaravel.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Ip2location\IP2ProxyLaravel\Facade;
3+
4+
use Illuminate\Support\Facades\Facade;
5+
6+
class IP2ProxyLaravel extends Facade
7+
{
8+
protected static function getFacadeAccessor()
9+
{
10+
return 'ip2proxylaravel';
11+
}
12+
}

src/IP2ProxyLaravel.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Ip2location\IP2ProxyLaravel;
4+
5+
class IP2ProxyLaravel
6+
{
7+
8+
public function get($ip)
9+
{
10+
$db = new \IP2Proxy\Database()
11+
$db->open($this->getDatabasePath(), \IP2Proxy\Database::FILE_IO);
12+
13+
$records = $db->getAll($ip);
14+
15+
$db->close();
16+
17+
return $records;
18+
}
19+
20+
private function getDatabasePath()
21+
{
22+
return config('ip2proxylaravel.ip2proxy.local.path');
23+
}
24+
25+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Ip2location\IP2ProxyLaravel;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use Illuminate\Foundation\AliasLoader;
7+
8+
class IP2ProxyLaravelServiceProvider extends ServiceProvider
9+
{
10+
/**
11+
* Bootstrap the application services.
12+
*
13+
* @return void
14+
*/
15+
public function boot()
16+
{
17+
$this->app->bind('ip2proxylaravel', IP2ProxyLaravel::class);
18+
}
19+
20+
/**
21+
* Register the application services.
22+
*
23+
* @return void
24+
*/
25+
public function register()
26+
{
27+
//Dynamically add IP2ProxyLaravel alias
28+
AliasLoader::getInstance()->alias('IP2ProxyLaravel', 'Ip2location\IP2ProxyLaravel\Facade\IP2ProxyLaravel');
29+
30+
$config = __DIR__.'/Config/ip2proxylaravel.php';
31+
32+
$this->publishes([
33+
$config => config_path('ip2proxylaravel.php'),
34+
], 'config');
35+
36+
$this->mergeConfigFrom( $config, 'ip2proxylaravel');
37+
38+
// $this->app['ip2proxylaravel'] = $this->app->share(function($app){
39+
// return new IP2ProxyLaravel;
40+
// });
41+
}
42+
}

tests/BasicTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Illuminate\Foundation\Testing\WithoutMiddleware;
4+
use Illuminate\Foundation\Testing\DatabaseMigrations;
5+
use Illuminate\Foundation\Testing\DatabaseTransactions;
6+
7+
class BasicTest extends TestCase
8+
{
9+
10+
public function testGet()
11+
{
12+
$result = IP2ProxyLaravel::get('1.2.3.4');
13+
$this->assertEquals($result['isProxy'], '1');
14+
}
15+
16+
}

0 commit comments

Comments
 (0)