Skip to content

Commit

Permalink
Add support for MCC/MNC
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Nov 17, 2021
1 parent 8e7adcd commit fdae39f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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
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
8 changes: 8 additions & 0 deletions tests/GeoIp2/Test/Database/ReaderTest.php
Original file line number Diff line number Diff line change
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 fdae39f

Please sign in to comment.