From fbf4583b3ee8d1f3dcbb194cd02fc146943af9e0 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 27 Oct 2014 16:30:40 -0500 Subject: [PATCH] Add support for Anonymous IP database --- maxmind-db | 2 +- src/GeoIp2/Database/Reader.php | 21 ++++++++++ src/GeoIp2/Model/AnonymousIp.php | 50 +++++++++++++++++++++++ tests/GeoIp2/Test/Database/ReaderTest.php | 14 +++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/GeoIp2/Model/AnonymousIp.php diff --git a/maxmind-db b/maxmind-db index 1d28147..e53ed8c 160000 --- a/maxmind-db +++ b/maxmind-db @@ -1 +1 @@ -Subproject commit 1d2814761753aefe32311cb917ab1e4f16d9fd7e +Subproject commit e53ed8cde6951be3bbd0fdb300d69c898b399a97 diff --git a/src/GeoIp2/Database/Reader.php b/src/GeoIp2/Database/Reader.php index 442a23e..a57b75d 100644 --- a/src/GeoIp2/Database/Reader.php +++ b/src/GeoIp2/Database/Reader.php @@ -91,6 +91,27 @@ class Reader implements ProviderInterface 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. * diff --git a/src/GeoIp2/Model/AnonymousIp.php b/src/GeoIp2/Model/AnonymousIp.php new file mode 100644 index 0000000..07f7800 --- /dev/null +++ b/src/GeoIp2/Model/AnonymousIp.php @@ -0,0 +1,50 @@ +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'); + } +} diff --git a/tests/GeoIp2/Test/Database/ReaderTest.php b/tests/GeoIp2/Test/Database/ReaderTest.php index 6a2d859..68a4732 100644 --- a/tests/GeoIp2/Test/Database/ReaderTest.php +++ b/tests/GeoIp2/Test/Database/ReaderTest.php @@ -88,6 +88,20 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $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() {