Skip to content

Commit 151972e

Browse files
Added support for AS domain, AS usage type and AS CIDR
1 parent cf14960 commit 151972e

File tree

11 files changed

+83
-14
lines changed

11 files changed

+83
-14
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 IP2Location
3+
Copyright (c) 2025 IP2Location
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Maven Central Version](https://img.shields.io/maven-central/v/com.ip2location/ip2location-java)](https://central.sonatype.com/artifact/com.ip2location/ip2location-java)
33

44

5-
This IP Geolocation Java component allows user to query an IP address for info such as the visitor’s country, region, city, ISP or company name. In addition, users can also determine extra useful geolocation information such as latitude, longitude, ZIP code, domain name, time zone, connection speed, IDD code, area code, weather station code, weather station name, MCC, MNC, mobile brand name, elevation, usage type, address type, IAB category, district, autonomous system number (ASN) and autonomous system (AS). It lookup the IP address from **IP2Location BIN Data** file. This data file can be downloaded at
5+
This IP Geolocation Java component allows user to query an IP address for info such as the visitor’s country, region, city, ISP or company name. In addition, users can also determine extra useful geolocation information such as latitude, longitude, ZIP code, domain name, time zone, connection speed, IDD code, area code, weather station code, weather station name, MCC, MNC, mobile brand name, elevation, usage type, address type, IAB category, district, autonomous system number (ASN), autonomous system (AS), AS domain, AS usage type and AS CIDR. It lookup the IP address from **IP2Location BIN Data** file. This data file can be downloaded at
66

77
* Free IP2Location IP Geolocation BIN Data: https://lite.ip2location.com
88
* Commercial IP2Location IP Geolocation BIN Data: https://www.ip2location.com/database/ip2location

com/ip2location/Country.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* <p>
1818
*
1919
* @author IP2Location.com
20-
* @version 8.12.2
20+
* @version 8.13.0
2121
*/
2222
public class Country {
2323
private final Map<String, Map<String, String>> records = new HashMap<>();

com/ip2location/IP2Location.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* <p>
3535
*
3636
* @author IP2Location.com
37-
* @version 8.12.2
37+
* @version 8.13.0
3838
*/
3939
public class IP2Location {
4040
private static final Pattern pattern = Pattern.compile("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"); // IPv4
@@ -75,6 +75,9 @@ public class IP2Location {
7575
private static final int[] DISTRICT_POSITION = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23};
7676
private static final int[] ASN_POSITION = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24};
7777
private static final int[] AS_POSITION = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25};
78+
private static final int[] ASDOMAIN_POSITION = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26};
79+
private static final int[] ASUSAGETYPE_POSITION = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27};
80+
private static final int[] ASCIDR_POSITION = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28};
7881
static final DecimalFormat GEO_COORDINATE_FORMAT;
7982

8083
static {
@@ -130,6 +133,9 @@ public class IP2Location {
130133
private int DISTRICT_POSITION_OFFSET;
131134
private int ASN_POSITION_OFFSET;
132135
private int AS_POSITION_OFFSET;
136+
private int ASDOMAIN_POSITION_OFFSET;
137+
private int ASUSAGETYPE_POSITION_OFFSET;
138+
private int ASCIDR_POSITION_OFFSET;
133139
private boolean COUNTRY_ENABLED;
134140
private boolean REGION_ENABLED;
135141
private boolean CITY_ENABLED;
@@ -154,6 +160,9 @@ public class IP2Location {
154160
private boolean DISTRICT_ENABLED;
155161
private boolean ASN_ENABLED;
156162
private boolean AS_ENABLED;
163+
private boolean ASDOMAIN_ENABLED;
164+
private boolean ASUSAGETYPE_ENABLED;
165+
private boolean ASCIDR_ENABLED;
157166

158167
public IP2Location() {
159168

@@ -413,6 +422,9 @@ private boolean LoadBIN() throws IOException {
413422
DISTRICT_POSITION_OFFSET = (DISTRICT_POSITION[dbtype] != 0) ? (DISTRICT_POSITION[dbtype] - 2) << 2 : 0;
414423
ASN_POSITION_OFFSET = (ASN_POSITION[dbtype] != 0) ? (ASN_POSITION[dbtype] - 2) << 2 : 0;
415424
AS_POSITION_OFFSET = (AS_POSITION[dbtype] != 0) ? (AS_POSITION[dbtype] - 2) << 2 : 0;
425+
ASDOMAIN_POSITION_OFFSET = (ASDOMAIN_POSITION[dbtype] != 0) ? (ASDOMAIN_POSITION[dbtype] - 2) << 2 : 0;
426+
ASUSAGETYPE_POSITION_OFFSET = (ASUSAGETYPE_POSITION[dbtype] != 0) ? (ASUSAGETYPE_POSITION[dbtype] - 2) << 2 : 0;
427+
ASCIDR_POSITION_OFFSET = (ASCIDR_POSITION[dbtype] != 0) ? (ASCIDR_POSITION[dbtype] - 2) << 2 : 0;
416428

417429
COUNTRY_ENABLED = (COUNTRY_POSITION[dbtype] != 0);
418430
REGION_ENABLED = (REGION_POSITION[dbtype] != 0);
@@ -438,6 +450,9 @@ private boolean LoadBIN() throws IOException {
438450
DISTRICT_ENABLED = (DISTRICT_POSITION[dbtype] != 0);
439451
ASN_ENABLED = (ASN_POSITION[dbtype] != 0);
440452
AS_ENABLED = (AS_POSITION[dbtype] != 0);
453+
ASDOMAIN_ENABLED = (ASDOMAIN_POSITION[dbtype] != 0);
454+
ASUSAGETYPE_ENABLED = (ASUSAGETYPE_POSITION[dbtype] != 0);
455+
ASCIDR_ENABLED = (ASCIDR_POSITION[dbtype] != 0);
441456

442457
if (_MetaData.getIndexed()) {
443458
int readLen = _IndexArrayIPv4.length;
@@ -791,6 +806,24 @@ public IPResult IPQuery(String IPAddress) throws IOException {
791806
} else {
792807
record.as = IPResult.NOT_SUPPORTED;
793808
}
809+
if (ASDOMAIN_ENABLED) {
810+
position = read32Row(row, ASDOMAIN_POSITION_OFFSET).longValue();
811+
record.asdomain = readStr(position, mydatabuffer, filehandle);
812+
} else {
813+
record.asdomain = IPResult.NOT_SUPPORTED;
814+
}
815+
if (ASUSAGETYPE_ENABLED) {
816+
position = read32Row(row, ASUSAGETYPE_POSITION_OFFSET).longValue();
817+
record.asusagetype = readStr(position, mydatabuffer, filehandle);
818+
} else {
819+
record.asusagetype = IPResult.NOT_SUPPORTED;
820+
}
821+
if (ASCIDR_ENABLED) {
822+
position = read32Row(row, ASCIDR_POSITION_OFFSET).longValue();
823+
record.ascidr = readStr(position, mydatabuffer, filehandle);
824+
} else {
825+
record.ascidr = IPResult.NOT_SUPPORTED;
826+
}
794827
record.status = "OK";
795828
break;
796829
} else {

com/ip2location/IP2LocationWebService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* <p>
2727
*
2828
* @author IP2Location.com
29-
* @version 8.12.2
29+
* @version 8.13.0
3030
*/
3131
public class IP2LocationWebService {
3232
private static final Pattern pattern = Pattern.compile("^[\\dA-Z]{10}$");

com/ip2location/IPResult.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* <p>
88
*
99
* @author IP2Location.com
10-
* @version 8.12.2
10+
* @version 8.13.0
1111
*/
1212
public class IPResult {
1313
static final String NOT_SUPPORTED = "Not_Supported";
@@ -37,9 +37,12 @@ public class IPResult {
3737
String district;
3838
String asn;
3939
String as;
40+
String asdomain;
41+
String asusagetype;
42+
String ascidr;
4043
String status;
4144
boolean delay = false;
42-
String version = "Version 8.12.2";
45+
String version = "Version 8.13.0";
4346

4447
IPResult(String ipstring) {
4548
ip_address = ipstring;
@@ -270,6 +273,33 @@ public String getAS() {
270273
return as;
271274
}
272275

276+
/**
277+
* This method to get AS domain.
278+
*
279+
* @return the AS domain.
280+
*/
281+
public String getASDomain() {
282+
return asdomain;
283+
}
284+
285+
/**
286+
* This method to get AS usage type.
287+
*
288+
* @return the AS usage type.
289+
*/
290+
public String getASUsageType() {
291+
return asusagetype;
292+
}
293+
294+
/**
295+
* This method to get AS CIDR.
296+
*
297+
* @return the AS CIDR.
298+
*/
299+
public String getASCIDR() {
300+
return ascidr;
301+
}
302+
273303
/**
274304
* This method to get status code of query.
275305
*
@@ -331,6 +361,9 @@ public String toString() {
331361
buf.append("\tDistrict = " + district + NL);
332362
buf.append("\tASN = " + asn + NL);
333363
buf.append("\tAS = " + as + NL);
364+
buf.append("\tASDomain = " + asdomain + NL);
365+
buf.append("\tASUsageType = " + asusagetype + NL);
366+
buf.append("\tASCIDR = " + ascidr + NL);
334367
return buf.toString();
335368
}
336369
}

com/ip2location/IPTools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* <p>
3535
*
3636
* @author IP2Location.com
37-
* @version 8.12.2
37+
* @version 8.13.0
3838
*/
3939
public class IPTools {
4040
private static final BigInteger MAX_IPV4_RANGE = new BigInteger("4294967295");

com/ip2location/Region.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* <p>
1919
*
2020
* @author IP2Location.com
21-
* @version 8.12.2
21+
* @version 8.13.0
2222
*/
2323
public class Region {
2424
private final Map<String, List<Map<String, String>>> records = new HashMap<>();

docs/source/code.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Retrieve geolocation information for an IP address.
4848
| district | District or county name. |
4949
| asn | Autonomous system number (ASN). BIN databases. |
5050
| as | Autonomous system (AS) name. |
51+
| asdomain | Domain name of the AS registrant. |
52+
| asusagetype | Usage type of the AS registrant. |
53+
| ascidr | CIDR range for the whole AS. |
5154
```
5255

5356
## IPTools Class

docs/source/conf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
# -- Project information
77

88
project = 'IP2Location Java'
9-
copyright = '2024, IP2Location'
9+
copyright = '2025, IP2Location'
1010
author = 'IP2Location'
1111

12-
release = '1.0.0'
13-
version = '1.0.0'
12+
release = '8.13.0'
13+
version = '8.13.0'
1414

1515
# -- General configuration
1616

@@ -61,4 +61,4 @@
6161

6262
html_title = "IP2Location Java"
6363

64-
# html_baseurl = "https://ip2location-go.readthedocs.io/en/latest/"
64+
# html_baseurl = "https://ip2location-java.readthedocs.io/en/latest/"

0 commit comments

Comments
 (0)