Skip to content

Commit 39618fc

Browse files
committed
Add MCC/MNC support
1 parent ccdc64f commit 39618fc

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-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.16.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. `getMobileCountryCode()` and
10+
`getMobileNetworkCode()` were added to `com.maxmind.geoip2.model.IspResponse`
11+
 for the GeoIP2 ISP database and `com.maxmind.geoip2.record.Traits` for the
12+
Enterprise database and the GeoIP2 City and Insights web services. We expect
13+
this data to be available by late January, 2022.
714
* Deprecated model constructors that exist for backwards compatibility.
815
These constructors are not generally used by users of this library
916
directly except perhaps when mocking the reader in tests.

src/main/java/com/maxmind/geoip2/model/IspResponse.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class IspResponse extends AsnResponse {
1515

1616
private final String isp;
1717
private final String organization;
18+
private final String mobileCountryCode;
19+
private final String mobileNetworkCode;
1820

1921
IspResponse() {
2022
this(null, null, null, null, null);
@@ -34,16 +36,50 @@ public IspResponse(
3436
this(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, isp, organization, null);
3537
}
3638

39+
/**
40+
* @deprecated This constructor exists for backwards compatibility. Will be
41+
* removed in the next major release.
42+
*/
43+
public IspResponse(
44+
Integer autonomousSystemNumber,
45+
String autonomousSystemOrganization,
46+
String ipAddress,
47+
String isp,
48+
String organization,
49+
Network network
50+
) {
51+
this(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, isp, null, null, organization, network);
52+
}
53+
54+
/**
55+
* @deprecated This constructor exists for backwards compatibility. Will be
56+
* removed in the next major release.
57+
*/
58+
public IspResponse(
59+
Long autonomousSystemNumber,
60+
String autonomousSystemOrganization,
61+
String ipAddress,
62+
String isp,
63+
String organization,
64+
Network network
65+
) {
66+
this(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, isp, null, null, organization, network);
67+
}
68+
3769
public IspResponse(
3870
@JsonProperty("autonomous_system_number") Integer autonomousSystemNumber,
3971
@JsonProperty("autonomous_system_organization") String autonomousSystemOrganization,
4072
@JacksonInject("ip_address") @JsonProperty("ip_address") String ipAddress,
4173
@JsonProperty("isp") String isp,
74+
@JsonProperty("mobile_country_code") String mobileCountryCode,
75+
@JsonProperty("mobile_network_code") String mobileNetworkCode,
4276
@JsonProperty("organization") String organization,
4377
@JacksonInject("network") @JsonProperty("network") @JsonDeserialize(using = NetworkDeserializer.class) Network network
4478
) {
4579
super(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, network);
4680
this.isp = isp;
81+
this.mobileCountryCode = mobileCountryCode;
82+
this.mobileNetworkCode = mobileNetworkCode;
4783
this.organization = organization;
4884
}
4985

@@ -53,6 +89,8 @@ public IspResponse(
5389
@MaxMindDbParameter(name="autonomous_system_organization") String autonomousSystemOrganization,
5490
@MaxMindDbParameter(name="ip_address") String ipAddress,
5591
@MaxMindDbParameter(name="isp") String isp,
92+
@MaxMindDbParameter(name="mobile_country_code") String mobileCountryCode,
93+
@MaxMindDbParameter(name="mobile_network_code") String mobileNetworkCode,
5694
@MaxMindDbParameter(name="organization") String organization,
5795
@MaxMindDbParameter(name="network") Network network
5896
) {
@@ -61,6 +99,8 @@ public IspResponse(
6199
autonomousSystemOrganization,
62100
ipAddress,
63101
isp,
102+
mobileCountryCode,
103+
mobileNetworkCode,
64104
organization,
65105
network
66106
);
@@ -76,6 +116,8 @@ public IspResponse(
76116
response.getAutonomousSystemOrganization(),
77117
ipAddress,
78118
response.getIsp(),
119+
response.getMobileCountryCode(),
120+
response.getMobileNetworkCode(),
79121
response.getOrganization(),
80122
network
81123
);
@@ -88,6 +130,26 @@ public String getIsp() {
88130
return this.isp;
89131
}
90132

133+
/**
134+
* @return The <a href="https://en.wikipedia.org/wiki/Mobile_country_code">
135+
* mobile country code (MCC)</a> associated with the IP address and ISP.
136+
* This property is available from the City and Insights web services and
137+
* the GeoIP2 Enterprise database.
138+
*/
139+
public String getMobileCountryCode() {
140+
return this.mobileCountryCode;
141+
}
142+
143+
/**
144+
* @return The <a href="https://en.wikipedia.org/wiki/Mobile_country_code">
145+
* mobile network code (MNC)</a> associated with the IP address and ISP.
146+
* This property is available from the City and Insights web services and
147+
* the GeoIP2 Enterprise database.
148+
*/
149+
public String getMobileNetworkCode() {
150+
return this.mobileNetworkCode;
151+
}
152+
91153
/**
92154
* @return The name of the organization associated with the IP address.
93155
*/

src/main/java/com/maxmind/geoip2/record/Traits.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public final class Traits extends AbstractRecord {
3636
private final boolean isSatelliteProvider;
3737
private final boolean isTorExitNode;
3838
private final String isp;
39+
private final String mobileCountryCode;
40+
private final String mobileNetworkCode;
3941
private final Network network;
4042
private final String organization;
4143
private final String userType;
@@ -160,6 +162,74 @@ public Traits(
160162
staticIpScore);
161163
}
162164

165+
/**
166+
* @deprecated This constructor exists for backwards compatibility. Will be
167+
* removed in the next major release.
168+
*/
169+
public Traits(
170+
Integer autonomousSystemNumber,
171+
String autonomousSystemOrganization,
172+
ConnectionType connectionType,
173+
String domain,
174+
String ipAddress,
175+
boolean isAnonymous,
176+
boolean isAnonymousProxy,
177+
boolean isAnonymousVpn,
178+
boolean isHostingProvider,
179+
boolean isLegitimateProxy,
180+
boolean isPublicProxy,
181+
boolean isResidentialProxy,
182+
boolean isSatelliteProvider,
183+
boolean isTorExitNode,
184+
String isp,
185+
Network network,
186+
String organization,
187+
String userType,
188+
Integer userCount,
189+
Double staticIpScore
190+
) {
191+
this(autonomousSystemNumber, autonomousSystemOrganization,
192+
connectionType, domain, ipAddress, isAnonymous,
193+
isAnonymousProxy, isAnonymousVpn, isHostingProvider,
194+
isLegitimateProxy, isPublicProxy, isResidentialProxy, isSatelliteProvider,
195+
isTorExitNode, isp, null, null, network,
196+
organization, userType, userCount, staticIpScore);
197+
}
198+
199+
/**
200+
* @deprecated This constructor exists for backwards compatibility. Will be
201+
* removed in the next major release.
202+
*/
203+
public Traits(
204+
Long autonomousSystemNumber,
205+
String autonomousSystemOrganization,
206+
String connectionType,
207+
String domain,
208+
String ipAddress,
209+
Boolean isAnonymous,
210+
Boolean isAnonymousProxy,
211+
Boolean isAnonymousVpn,
212+
Boolean isHostingProvider,
213+
Boolean isLegitimateProxy,
214+
Boolean isPublicProxy,
215+
Boolean isResidentialProxy,
216+
Boolean isSatelliteProvider,
217+
Boolean isTorExitNode,
218+
String isp,
219+
Network network,
220+
String organization,
221+
String userType,
222+
Integer userCount,
223+
Double staticIpScore
224+
) {
225+
this(autonomousSystemNumber, autonomousSystemOrganization,
226+
connectionType, domain, ipAddress, isAnonymous,
227+
isAnonymousProxy, isAnonymousVpn, isHostingProvider,
228+
isLegitimateProxy, isPublicProxy, isResidentialProxy, isSatelliteProvider,
229+
isTorExitNode, isp, null, null, network,
230+
organization, userType, userCount, staticIpScore);
231+
}
232+
163233
public Traits(
164234
@JsonProperty("autonomous_system_number") Integer autonomousSystemNumber,
165235
@JsonProperty("autonomous_system_organization") String autonomousSystemOrganization,
@@ -176,6 +246,8 @@ public Traits(
176246
@JsonProperty("is_satellite_provider") boolean isSatelliteProvider,
177247
@JsonProperty("is_tor_exit_node") boolean isTorExitNode,
178248
@JsonProperty("isp") String isp,
249+
@JsonProperty("mobile_country_code") String mobileCountryCode,
250+
@JsonProperty("mobile_network_code") String mobileNetworkCode,
179251
@JacksonInject("network") @JsonProperty("network") @JsonDeserialize(using = NetworkDeserializer.class) Network network,
180252
@JsonProperty("organization") String organization,
181253
@JsonProperty("user_type") String userType,
@@ -197,6 +269,8 @@ public Traits(
197269
this.isSatelliteProvider = isSatelliteProvider;
198270
this.isTorExitNode = isTorExitNode;
199271
this.isp = isp;
272+
this.mobileCountryCode = mobileCountryCode;
273+
this.mobileNetworkCode = mobileNetworkCode;
200274
this.network = network;
201275
this.organization = organization;
202276
this.userType = userType;
@@ -221,6 +295,8 @@ public Traits(
221295
@MaxMindDbParameter(name="is_satellite_provider") Boolean isSatelliteProvider,
222296
@MaxMindDbParameter(name="is_tor_exit_node") Boolean isTorExitNode,
223297
@MaxMindDbParameter(name="isp") String isp,
298+
@MaxMindDbParameter(name="mobile_country_code") String mobileCountryCode,
299+
@MaxMindDbParameter(name="mobile_network_code") String mobileNetworkCode,
224300
@MaxMindDbParameter(name="network") Network network,
225301
@MaxMindDbParameter(name="organization") String organization,
226302
@MaxMindDbParameter(name="user_type") String userType,
@@ -243,6 +319,8 @@ public Traits(
243319
isSatelliteProvider != null ? isSatelliteProvider : false,
244320
isTorExitNode != null ? isTorExitNode : false,
245321
isp,
322+
mobileCountryCode,
323+
mobileNetworkCode,
246324
network,
247325
organization,
248326
userType,
@@ -272,6 +350,8 @@ public Traits(
272350
traits.isSatelliteProvider(),
273351
traits.isTorExitNode(),
274352
traits.getIsp(),
353+
traits.getMobileCountryCode(),
354+
traits.getMobileNetworkCode(),
275355
network,
276356
traits.getOrganization(),
277357
traits.getUserType(),
@@ -461,6 +541,26 @@ public boolean isTorExitNode() {
461541
return this.isTorExitNode;
462542
}
463543

544+
/**
545+
* @return The <a href="https://en.wikipedia.org/wiki/Mobile_country_code">
546+
* mobile country code (MCC)</a> associated with the IP address and ISP.
547+
* This property is available from the City and Insights web services and
548+
* the GeoIP2 Enterprise database.
549+
*/
550+
public String getMobileCountryCode() {
551+
return this.mobileCountryCode;
552+
}
553+
554+
/**
555+
* @return The <a href="https://en.wikipedia.org/wiki/Mobile_country_code">
556+
* mobile network code (MNC)</a> associated with the IP address and ISP.
557+
* This property is available from the City and Insights web services and
558+
* the GeoIP2 Enterprise database.
559+
*/
560+
public String getMobileNetworkCode() {
561+
return this.mobileNetworkCode;
562+
}
563+
464564
/**
465565
* @return The network associated with the record. In particular, this is
466566
* the largest network where all of the fields besides IP address have the

src/test/java/com/maxmind/geoip2/DatabaseReaderTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ public void testEnterprise() throws Exception {
349349
EnterpriseResponse tryResponse = reader.tryEnterprise(ipAddress).get();
350350
assertEquals(response.toJson(), tryResponse.toJson());
351351

352+
ipAddress = InetAddress.getByName("149.101.100.0");
353+
response = reader.enterprise(ipAddress);
354+
assertEquals("310", response.getTraits().getMobileCountryCode());
355+
assertEquals("004", response.getTraits().getMobileNetworkCode());
356+
352357
// Test that the city and country methods can be called without
353358
// an exception
354359
reader.city(ipAddress);
@@ -374,6 +379,11 @@ public void testIsp() throws Exception {
374379

375380
IspResponse tryResponse = reader.tryIsp(ipAddress).get();
376381
assertEquals(response.toJson(), tryResponse.toJson());
382+
383+
ipAddress = InetAddress.getByName("149.101.100.0");
384+
response = reader.isp(ipAddress);
385+
assertEquals("310", response.getMobileCountryCode());
386+
assertEquals("004", response.getMobileNetworkCode());
377387
}
378388
}
379389

0 commit comments

Comments
 (0)