Add support for Anonymous IP database

This commit is contained in:
Dave Rolsky 2014-10-27 16:30:40 -05:00
parent 18686e11ac
commit fbf4583b3e
4 changed files with 86 additions and 1 deletions

@ -1 +1 @@
Subproject commit 1d2814761753aefe32311cb917ab1e4f16d9fd7e Subproject commit e53ed8cde6951be3bbd0fdb300d69c898b399a97

View File

@ -91,6 +91,27 @@ class Reader implements ProviderInterface
return $this->modelFor('Country', 'Country', $ipAddress); return $this->modelFor('Country', 'Country', $ipAddress);
} }
/**
* This method returns a GeoIP2 Anonymous IP model.
*
* @param string $ipAddress IPv4 or IPv6 address as a string.
*
* @return \GeoIp2\Model\Domain
*
* @throws \GeoIp2\Exception\AddressNotFoundException if the address is
* not in the database.
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
* is corrupt or invalid
*/
public function anonymousIp($ipAddress)
{
return $this->flatModelFor(
'AnonymousIp',
'GeoIP2-Anonymous-IP',
$ipAddress
);
}
/** /**
* This method returns a GeoIP2 Connection Type model. * This method returns a GeoIP2 Connection Type model.
* *

View File

@ -0,0 +1,50 @@
<?php
namespace GeoIp2\Model;
/**
* This class provides the GeoIP2 Anonymous IP model.
*
* @property boolean $isAnonymous This is true if the IP address belongs to
* any sort of anonymous network.
*
* @property boolean $isAnonymousVpn This is true if the IP address belongs to
* an anonymous Vpn system.
*
* @property boolean $isHostingProvider This is true if the IP address belongs
* to a hosting provider.
*
* @property boolean $isPublicProxy This is true if the IP address belongs to
* a public proxy.
*
* @property boolean $isAnonymous This is true if the IP address is a Tor exit
* node.
*
* @property string $ipAddress The IP address that the data in the model is
* for.
*
*/
class AnonymousIp extends AbstractModel
{
protected $isAnonymous;
protected $isAnonymousVpn;
protected $isHostingProvider;
protected $isPublicProxy;
protected $isTorExitNode;
protected $ipAddress;
/**
* @ignore
*/
public function __construct($raw)
{
parent::__construct($raw);
$this->isAnonymous = $this->get('is_anonymous');
$this->isAnonymousVpn = $this->get('is_anonymous_vpn');
$this->isHostingProvider = $this->get('is_hosting_provider');
$this->isPublicProxy = $this->get('is_public_proxy');
$this->isTorExitNode = $this->get('is_tor_exit_node');
$this->ipAddress = $this->get('ip_address');
}
}

View File

@ -88,6 +88,20 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$reader->close(); $reader->close();
} }
public function testAnonymousIp()
{
$reader = new Reader('maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb');
$ipAddress = '1.2.0.1';
$record = $reader->anonymousIp($ipAddress);
$this->assertEquals(1, $record->isAnonymous);
$this->assertEquals(1, $record->isAnonymousVpn);
$this->assertEquals(0, $record->isHostingProvider);
$this->assertEquals(0, $record->isPublicProxy);
$this->assertEquals(0, $record->isTorExitNode);
$this->assertEquals($ipAddress, $record->ipAddress);
$reader->close();
}
public function testConnectionType() public function testConnectionType()
{ {