Skip to content

Commit

Permalink
Merge pull request #172 from maxmind/greg/mcc-mnc
Browse files Browse the repository at this point in the history
Add MCC/MNC support
  • Loading branch information
ugexe authored Nov 17, 2021
2 parents 5397d11 + fdae39f commit a320c2c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 12 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
CHANGELOG
=========

2.12.0
-------------------

* Support for mobile country code (MCC) and mobile network codes (MNC) was
 added for the GeoIP2 ISP and Enterprise databases as well as the GeoIP2
 City and Insights web services. `$mobileCountryCode` and
`$mobileNetworkCode` properties were added to `GeoIp2\Model\Isp`
 for the GeoIP2 ISP database and `GeoIp2\Record\Traits` for the Enterprise
database and the GeoIP2 City and Insights web services. We expect this data
to be available by late January, 2022.
* `geoip2.phar` is now generated with Box 3.x.

2.11.0 (2020-10-01)
-------------------

Expand Down
8 changes: 3 additions & 5 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"main": "phar-stub.php",
"output": "geoip2.phar",
"compactors": [
"Herrera\\Box\\Compactor\\Composer",
"Herrera\\Box\\Compactor\\Json",
"Herrera\\Box\\Compactor\\Php"
"KevinGH\\Box\\Compactor\\Php",
"KevinGH\\Box\\Compactor\\Json"
],
"files": [
"LICENSE"
Expand Down Expand Up @@ -38,6 +37,5 @@
}
],
"git-version": "git-version",
"shebang": false,
"stub": true
"shebang": false
}
6 changes: 3 additions & 3 deletions dev-bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ php composer.phar update --no-dev
perl -pi -e "s/(?<=const VERSION = ').+?(?=';)/$tag/g" src/WebService/Client.php

if [ ! -f box.phar ]; then
wget -O box.phar "https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar"
wget -O box.phar "https://github.com/box-project/box/releases/download/3.13.0/box.phar"
fi

php box.phar build
php box.phar compile

phar_test=$(./dev-bin/phar-test.php)
if [[ -n $phar_test ]]; then
Expand Down Expand Up @@ -88,7 +88,7 @@ if [ -n "$(git status --porcelain)" ]; then
fi

# Using Composer is possible, but they don't recommend it.
wget -O phpDocumentor.phar https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.0.0/phpDocumentor.phar
wget -O phpDocumentor.phar https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.1.2/phpDocumentor.phar

# Use cache dir in /tmp as otherwise cache files get into the output directory.
cachedir="/tmp/phpdoc-$$-$RANDOM"
Expand Down
2 changes: 1 addition & 1 deletion maxmind-db
Submodule maxmind-db updated 46 files
+15 −11 MaxMind-DB-spec.md
+ MaxMind-DB-test-metadata-pointers.mmdb
+81 −48 source-data/GeoIP2-City-Test.json
+20 −0 source-data/GeoIP2-Connection-Type-Test.json
+46 −58 source-data/GeoIP2-Country-Test.json
+61 −3 source-data/GeoIP2-Enterprise-Test.json
+10 −0 source-data/GeoIP2-ISP-Test.json
+61 −4 source-data/GeoIP2-Precision-Enterprise-Test.json
+4,091 −8 source-data/GeoLite2-ASN-Test.json
+12,804 −0 source-data/GeoLite2-City-Test.json
+11,280 −0 source-data/GeoLite2-Country-Test.json
+ test-data/GeoIP2-Anonymous-IP-Test.mmdb
+ test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb
+ test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb
+ test-data/GeoIP2-City-Test.mmdb
+ test-data/GeoIP2-Connection-Type-Test.mmdb
+ test-data/GeoIP2-Country-Test.mmdb
+ test-data/GeoIP2-DensityIncome-Test.mmdb
+ test-data/GeoIP2-Domain-Test.mmdb
+ test-data/GeoIP2-Enterprise-Test.mmdb
+ test-data/GeoIP2-ISP-Test.mmdb
+ test-data/GeoIP2-Precision-Enterprise-Test.mmdb
+ test-data/GeoIP2-Static-IP-Score-Test.mmdb
+ test-data/GeoIP2-User-Count-Test.mmdb
+ test-data/GeoLite2-ASN-Test.mmdb
+ test-data/GeoLite2-City-Test.mmdb
+ test-data/GeoLite2-Country-Test.mmdb
+ test-data/MaxMind-DB-no-ipv4-search-tree.mmdb
+ test-data/MaxMind-DB-string-value-entries.mmdb
+ test-data/MaxMind-DB-test-broken-pointers-24.mmdb
+ test-data/MaxMind-DB-test-broken-search-tree-24.mmdb
+ test-data/MaxMind-DB-test-decoder.mmdb
+ test-data/MaxMind-DB-test-ipv4-24.mmdb
+ test-data/MaxMind-DB-test-ipv4-28.mmdb
+ test-data/MaxMind-DB-test-ipv4-32.mmdb
+ test-data/MaxMind-DB-test-ipv6-24.mmdb
+ test-data/MaxMind-DB-test-ipv6-28.mmdb
+ test-data/MaxMind-DB-test-ipv6-32.mmdb
+ test-data/MaxMind-DB-test-metadata-pointers.mmdb
+ test-data/MaxMind-DB-test-mixed-24.mmdb
+ test-data/MaxMind-DB-test-mixed-28.mmdb
+ test-data/MaxMind-DB-test-mixed-32.mmdb
+ test-data/MaxMind-DB-test-nested.mmdb
+ test-data/MaxMind-DB-test-pointer-decoder.mmdb
+3 −3 test-data/README.md
+9 −5 test-data/write-test-data.pl
16 changes: 16 additions & 0 deletions src/Model/Isp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
* address.
* @property-read string|null $isp The name of the ISP associated with the IP
* address.
* @property-read string|null $mobileCountryCode The [mobile country code
* (MCC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
* the IP address and ISP.
* @property-read string|null $mobileNetworkCode The [mobile network code
* (MNC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
* the IP address and ISP.
* @property-read string|null $organization The name of the organization associated
* with the IP address.
* @property-read string $ipAddress The IP address that the data in the model is
Expand All @@ -38,6 +44,14 @@ class Isp extends AbstractModel
* @var string|null
*/
protected $isp;
/**
* @var string|null
*/
protected $mobileCountryCode;
/**
* @var string|null
*/
protected $mobileNetworkCode;
/**
* @var string|null
*/
Expand All @@ -61,6 +75,8 @@ public function __construct(array $raw)
$this->autonomousSystemOrganization =
$this->get('autonomous_system_organization');
$this->isp = $this->get('isp');
$this->mobileCountryCode = $this->get('mobile_country_code');
$this->mobileNetworkCode = $this->get('mobile_network_code');
$this->organization = $this->get('organization');

$ipAddress = $this->get('ip_address');
Expand Down
10 changes: 10 additions & 0 deletions src/Record/Traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
* @property-read string|null $organization The name of the organization associated
* with the IP address. This attribute is only available from the City and
* Insights web services and the GeoIP2 Enterprise database.
* @property-read string|null $mobileCountryCode The [mobile country code
* (MCC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
* the IP address and ISP. This property is available from the City and
* Insights web services and the GeoIP2 Enterprise database.
* @property-read string|null $mobileNetworkCode The [mobile network code
* (MNC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
* the IP address and ISP. This property is available from the City and
* Insights web services and the GeoIP2 Enterprise database.
* @property-read float|null $staticIpScore An indicator of how static or
* dynamic an IP address is. This property is only available from GeoIP2
* Precision Insights.
Expand Down Expand Up @@ -130,6 +138,8 @@ class Traits extends AbstractRecord
'isResidentialProxy',
'isSatelliteProvider',
'isTorExitNode',
'mobileCountryCode',
'mobileNetworkCode',
'network',
'organization',
'staticIpScore',
Expand Down
14 changes: 11 additions & 3 deletions tests/GeoIp2/Test/Database/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public function testHasIpAddressAndNetwork(string $type, string $method): void
public function testIsInEuropeanUnion(string $type, string $method): void
{
$reader = new Reader("maxmind-db/test-data/GeoIP2-$type-Test.mmdb");
$record = $reader->{$method}('81.2.69.160');
$record = $reader->{$method}('2a02:cfc0::');
$this->assertTrue(
$record->country->isInEuropeanUnion,
'country is_in_european_union is true'
);
$this->assertFalse(
$this->assertTrue(
$record->registeredCountry->isInEuropeanUnion,
'registered_country is_in_european_union is false'
'registered_country is_in_european_union is true'
);
$reader->close();
}
Expand Down Expand Up @@ -210,6 +210,10 @@ public function testEnterprise(): void
$this->assertSame($ipAddress, $record->traits->ipAddress);
$this->assertSame('74.209.16.0/20', $record->traits->network);

$record = $reader->enterprise('149.101.100.0');
$this->assertSame('310', $record->traits->mobileCountryCode);
$this->assertSame('004', $record->traits->mobileNetworkCode);

$reader->close();
}

Expand All @@ -231,6 +235,10 @@ public function testIsp(): void
$this->assertSame($ipAddress, $record->ipAddress);
$this->assertSame('1.128.0.0/11', $record->network);

$record = $reader->isp('149.101.100.0');
$this->assertSame('310', $record->mobileCountryCode);
$this->assertSame('004', $record->mobileNetworkCode);

$reader->close();
}

Expand Down
14 changes: 14 additions & 0 deletions tests/GeoIp2/Test/Model/InsightsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function testFull(): void
'is_satellite_provider' => true,
'is_tor_exit_node' => true,
'isp' => 'Comcast',
'mobile_country_code' => '310',
'mobile_network_code' => '004',
'organization' => 'Blorg',
'static_ip_score' => 1.3,
'user_count' => 2,
Expand Down Expand Up @@ -193,6 +195,18 @@ public function testFull(): void
'$model->traits->isAnonymousProxy is false'
);

$this->assertSame(
'310',
$model->traits->mobileCountryCode,
'mobileCountryCode is correct'
);

$this->assertSame(
'004',
$model->traits->mobileNetworkCode,
'mobileNetworkCode is correct'
);

$this->assertSame(
1.3,
$model->traits->staticIpScore,
Expand Down

0 comments on commit a320c2c

Please sign in to comment.