Skip to content

Commit fdae39f

Browse files
committed
Add support for MCC/MNC
1 parent 8e7adcd commit fdae39f

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ CHANGELOG
44
2.12.0
55
-------------------
66

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

916
2.11.0 (2020-10-01)

src/Model/Isp.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
* address.
1717
* @property-read string|null $isp The name of the ISP associated with the IP
1818
* address.
19+
* @property-read string|null $mobileCountryCode The [mobile country code
20+
* (MCC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
21+
* the IP address and ISP.
22+
* @property-read string|null $mobileNetworkCode The [mobile network code
23+
* (MNC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
24+
* the IP address and ISP.
1925
* @property-read string|null $organization The name of the organization associated
2026
* with the IP address.
2127
* @property-read string $ipAddress The IP address that the data in the model is
@@ -38,6 +44,14 @@ class Isp extends AbstractModel
3844
* @var string|null
3945
*/
4046
protected $isp;
47+
/**
48+
* @var string|null
49+
*/
50+
protected $mobileCountryCode;
51+
/**
52+
* @var string|null
53+
*/
54+
protected $mobileNetworkCode;
4155
/**
4256
* @var string|null
4357
*/
@@ -61,6 +75,8 @@ public function __construct(array $raw)
6175
$this->autonomousSystemOrganization =
6276
$this->get('autonomous_system_organization');
6377
$this->isp = $this->get('isp');
78+
$this->mobileCountryCode = $this->get('mobile_country_code');
79+
$this->mobileNetworkCode = $this->get('mobile_network_code');
6480
$this->organization = $this->get('organization');
6581

6682
$ipAddress = $this->get('ip_address');

src/Record/Traits.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
* @property-read string|null $organization The name of the organization associated
7777
* with the IP address. This attribute is only available from the City and
7878
* Insights web services and the GeoIP2 Enterprise database.
79+
* @property-read string|null $mobileCountryCode The [mobile country code
80+
* (MCC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
81+
* the IP address and ISP. This property is available from the City and
82+
* Insights web services and the GeoIP2 Enterprise database.
83+
* @property-read string|null $mobileNetworkCode The [mobile network code
84+
* (MNC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
85+
* the IP address and ISP. This property is available from the City and
86+
* Insights web services and the GeoIP2 Enterprise database.
7987
* @property-read float|null $staticIpScore An indicator of how static or
8088
* dynamic an IP address is. This property is only available from GeoIP2
8189
* Precision Insights.
@@ -130,6 +138,8 @@ class Traits extends AbstractRecord
130138
'isResidentialProxy',
131139
'isSatelliteProvider',
132140
'isTorExitNode',
141+
'mobileCountryCode',
142+
'mobileNetworkCode',
133143
'network',
134144
'organization',
135145
'staticIpScore',

tests/GeoIp2/Test/Database/ReaderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ public function testEnterprise(): void
210210
$this->assertSame($ipAddress, $record->traits->ipAddress);
211211
$this->assertSame('74.209.16.0/20', $record->traits->network);
212212

213+
$record = $reader->enterprise('149.101.100.0');
214+
$this->assertSame('310', $record->traits->mobileCountryCode);
215+
$this->assertSame('004', $record->traits->mobileNetworkCode);
216+
213217
$reader->close();
214218
}
215219

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

238+
$record = $reader->isp('149.101.100.0');
239+
$this->assertSame('310', $record->mobileCountryCode);
240+
$this->assertSame('004', $record->mobileNetworkCode);
241+
234242
$reader->close();
235243
}
236244

tests/GeoIp2/Test/Model/InsightsTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public function testFull(): void
7878
'is_satellite_provider' => true,
7979
'is_tor_exit_node' => true,
8080
'isp' => 'Comcast',
81+
'mobile_country_code' => '310',
82+
'mobile_network_code' => '004',
8183
'organization' => 'Blorg',
8284
'static_ip_score' => 1.3,
8385
'user_count' => 2,
@@ -193,6 +195,18 @@ public function testFull(): void
193195
'$model->traits->isAnonymousProxy is false'
194196
);
195197

198+
$this->assertSame(
199+
'310',
200+
$model->traits->mobileCountryCode,
201+
'mobileCountryCode is correct'
202+
);
203+
204+
$this->assertSame(
205+
'004',
206+
$model->traits->mobileNetworkCode,
207+
'mobileNetworkCode is correct'
208+
);
209+
196210
$this->assertSame(
197211
1.3,
198212
$model->traits->staticIpScore,

0 commit comments

Comments
 (0)