Skip to content

Commit e335a20

Browse files
committed
Added support for PX9 to PX10 packages
1 parent b7fe4e7 commit e335a20

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# IP2Proxy Java Component
22

3-
This component allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range and search engine robots (SES). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
3+
This component allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range, search engine robots (SES) and residential (RES). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
44

55
* Free IP2Proxy BIN Data: https://lite.ip2location.com
66
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy
@@ -19,28 +19,29 @@ Below are the methods supported in this class.
1919
|---|---|
2020
|Open|Open the IP2Proxy BIN data for lookup. Please see the **Usage** section of the 2 modes supported to load the BIN data file.|
2121
|Close|Close and clean up the file pointer.|
22-
|GetPackageVersion|Get the package version (1 to 8 for PX1 to PX8 respectively).|
22+
|GetPackageVersion|Get the package version (1 to 10 for PX1 to PX10 respectively).|
2323
|GetModuleVersion|Get the module version.|
2424
|GetDatabaseVersion|Get the database version.|
2525
|IsProxy|Check whether if an IP address was a proxy. Returned value:<ul><li>-1 : errors</li><li>0 : not a proxy</li><li>1 : a proxy</li><li>2 : a data center IP address or search engine robot</li></ul>|
2626
|GetAll|Return the proxy information in an object.|
27-
|GetProxyType|Return the proxy type. Please visit <a href="https://www.ip2location.com/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" target="_blank">IP2Location</a> for the list of proxy types supported|
27+
|GetProxyType|Return the proxy type. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of proxy types supported|
2828
|GetCountryShort|Return the ISO3166-1 country code (2-digits) of the proxy.|
2929
|GetCountryLong|Return the ISO3166-1 country name of the proxy.|
3030
|GetRegion|Return the ISO3166-2 region name of the proxy. Please visit <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 Subdivision Code</a> for the information of ISO3166-2 supported|
3131
|GetCity|Return the city name of the proxy.|
3232
|GetISP|Return the ISP name of the proxy.|
3333
|GetDomain|Return the domain name of the proxy.|
34-
|GetUsageType|Return the usage type classification of the proxy. Please visit <a href="https://www.ip2location.com/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" target="_blank">IP2Location</a> for the list of usage types supported.|
34+
|GetUsageType|Return the usage type classification of the proxy. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of usage types supported.|
3535
|GetASN|Return the autonomous system number of the proxy.|
3636
|GetAS|Return the autonomous system name of the proxy.|
3737
|GetLastSeen|Return the number of days that the proxy was last seen.|
38+
|GetThreat|Return the threat type of the proxy.|
3839

3940
## Usage
4041

4142
Open and read IP2Proxy binary database. There are 2 modes:
4243

43-
1. **IOModes.IP2PROXY_FILE_IO** - File I/O reading. Slower look, but low resource consuming. This is the default.
44+
1. **IOModes.IP2PROXY_FILE_IO** - File I/O reading. Slower lookup, but low resource consuming. This is the default.
4445
2. **IOModes.IP2PROXY_MEMORY_MAPPED** - Stores whole IP2Proxy database into a memory-mapped file. Extremely resources consuming. Do not use this mode if your system do not have enough memory.
4546

4647
```java
@@ -67,10 +68,11 @@ public class Main {
6768
String ASN;
6869
String AS;
6970
String LastSeen;
71+
String Threat;
7072

7173
String IP = "221.121.146.0";
7274

73-
if (Proxy.Open("/usr/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN", IP2Proxy.IOModes.IP2PROXY_MEMORY_MAPPED) == 0) {
75+
if (Proxy.Open("/usr/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.BIN", IP2Proxy.IOModes.IP2PROXY_MEMORY_MAPPED) == 0) {
7476
System.out.println("GetModuleVersion: " + Proxy.GetModuleVersion());
7577
System.out.println("GetPackageVersion: " + Proxy.GetPackageVersion());
7678
System.out.println("GetDatabaseVersion: " + Proxy.GetDatabaseVersion());
@@ -89,6 +91,7 @@ public class Main {
8991
System.out.println("ASN: " + All.ASN);
9092
System.out.println("AS: " + All.AS);
9193
System.out.println("Last_Seen: " + All.Last_Seen);
94+
System.out.println("Threat: " + All.Threat);
9295

9396
// reading individual fields
9497
IsProxy = Proxy.IsProxy(IP);
@@ -126,6 +129,9 @@ public class Main {
126129

127130
LastSeen = Proxy.GetLastSeen(IP);
128131
System.out.println("LastSeen: " + LastSeen);
132+
133+
Threat = Proxy.GetThreat(IP);
134+
System.out.println("Threat: " + Threat);
129135
}
130136
else {
131137
System.out.println("Error reading BIN file.");

com/ip2proxy/IP2Proxy.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,21 @@ private enum Modes {
5353
ASN,
5454
AS,
5555
LAST_SEEN,
56+
THREAT,
5657
ALL;
5758
}
5859

59-
private static final int COUNTRY_POSITION[] = {0, 2, 3, 3, 3, 3, 3, 3, 3};
60-
private static final int REGION_POSITION[] = {0, 0, 0, 4, 4, 4, 4, 4, 4};
61-
private static final int CITY_POSITION[] = {0, 0, 0, 5, 5, 5, 5, 5, 5};
62-
private static final int ISP_POSITION[] = {0, 0, 0, 0, 6, 6, 6, 6, 6};
63-
private static final int PROXYTYPE_POSITION[] = {0, 0, 2, 2, 2, 2, 2, 2, 2};
64-
private static final int DOMAIN_POSITION[] = {0, 0, 0, 0, 0, 7, 7, 7, 7};
65-
private static final int USAGETYPE_POSITION[] = {0, 0, 0, 0, 0, 0, 8, 8, 8};
66-
private static final int ASN_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 9, 9};
67-
private static final int AS_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 10, 10};
68-
private static final int LASTSEEN_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 0, 11};
60+
private static final int COUNTRY_POSITION[] = {0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
61+
private static final int REGION_POSITION[] = {0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4};
62+
private static final int CITY_POSITION[] = {0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5};
63+
private static final int ISP_POSITION[] = {0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6};
64+
private static final int PROXYTYPE_POSITION[] = {0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2};
65+
private static final int DOMAIN_POSITION[] = {0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7};
66+
private static final int USAGETYPE_POSITION[] = {0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8};
67+
private static final int ASN_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9};
68+
private static final int AS_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10};
69+
private static final int LASTSEEN_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11};
70+
private static final int THREAT_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12};
6971

7072
private MappedByteBuffer _IPv4Buffer = null;
7173
private MappedByteBuffer _IPv6Buffer = null;
@@ -103,6 +105,7 @@ private enum Modes {
103105
private int ASN_POSITION_OFFSET;
104106
private int AS_POSITION_OFFSET;
105107
private int LASTSEEN_POSITION_OFFSET;
108+
private int THREAT_POSITION_OFFSET;
106109

107110
private boolean COUNTRY_ENABLED;
108111
private boolean REGION_ENABLED;
@@ -114,8 +117,9 @@ private enum Modes {
114117
private boolean ASN_ENABLED;
115118
private boolean AS_ENABLED;
116119
private boolean LASTSEEN_ENABLED;
120+
private boolean THREAT_ENABLED;
117121

118-
private static final String _ModuleVersion = "2.2.0";
122+
private static final String _ModuleVersion = "2.3.0";
119123

120124
public IP2Proxy() {
121125

@@ -258,6 +262,15 @@ public String GetLastSeen(String IP) throws IOException {
258262
return ProxyQuery(IP, Modes.LAST_SEEN).Last_Seen;
259263
}
260264

265+
/**
266+
* This function returns the threat type of the proxy.
267+
* @param IP IP Address you wish to query
268+
* @return Threat type of the proxy
269+
*/
270+
public String GetThreat(String IP) throws IOException {
271+
return ProxyQuery(IP, Modes.THREAT).Threat;
272+
}
273+
261274
/**
262275
* This function returns proxy result.
263276
* @param IP IP Address you wish to query
@@ -383,6 +396,7 @@ private boolean LoadBIN() throws IOException {
383396
// ASN_POSITION_OFFSET = (ASN_POSITION[_DBType] != 0) ? (ASN_POSITION[_DBType] - 1) << 2 : 0;
384397
// AS_POSITION_OFFSET = (AS_POSITION[_DBType] != 0) ? (AS_POSITION[_DBType] - 1) << 2 : 0;
385398
// LASTSEEN_POSITION_OFFSET = (LASTSEEN_POSITION[_DBType] != 0) ? (LASTSEEN_POSITION[_DBType] - 1) << 2 : 0;
399+
// THREAT_POSITION_OFFSET = (THREAT_POSITION[_DBType] != 0) ? (THREAT_POSITION[_DBType] - 1) << 2 : 0;
386400

387401
// slightly different offset for reading by row
388402
COUNTRY_POSITION_OFFSET = (COUNTRY_POSITION[_DBType] != 0) ? (COUNTRY_POSITION[_DBType] - 2) << 2 : 0;
@@ -395,6 +409,7 @@ private boolean LoadBIN() throws IOException {
395409
ASN_POSITION_OFFSET = (ASN_POSITION[_DBType] != 0) ? (ASN_POSITION[_DBType] - 2) << 2 : 0;
396410
AS_POSITION_OFFSET = (AS_POSITION[_DBType] != 0) ? (AS_POSITION[_DBType] - 2) << 2 : 0;
397411
LASTSEEN_POSITION_OFFSET = (LASTSEEN_POSITION[_DBType] != 0) ? (LASTSEEN_POSITION[_DBType] - 2) << 2 : 0;
412+
THREAT_POSITION_OFFSET = (THREAT_POSITION[_DBType] != 0) ? (THREAT_POSITION[_DBType] - 2) << 2 : 0;
398413

399414

400415
COUNTRY_ENABLED = (COUNTRY_POSITION[_DBType] != 0) ? true : false;
@@ -407,6 +422,7 @@ private boolean LoadBIN() throws IOException {
407422
ASN_ENABLED = (ASN_POSITION[_DBType] != 0) ? true : false;
408423
AS_ENABLED = (AS_POSITION[_DBType] != 0) ? true : false;
409424
LASTSEEN_ENABLED = (LASTSEEN_POSITION[_DBType] != 0) ? true : false;
425+
THREAT_ENABLED = (THREAT_POSITION[_DBType] != 0) ? true : false;
410426

411427
final MappedByteBuffer _IndexBuffer = InChannel.map(FileChannel.MapMode.READ_ONLY, _IndexBaseAddr - 1, _BaseAddr - _IndexBaseAddr); // reading indexes
412428
_IndexBuffer.order(ByteOrder.LITTLE_ENDIAN);
@@ -509,6 +525,7 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
509525
Result.ASN = MSG_INVALID_IP;
510526
Result.AS = MSG_INVALID_IP;
511527
Result.Last_Seen = MSG_INVALID_IP;
528+
Result.Threat = MSG_INVALID_IP;
512529
return Result;
513530
}
514531

@@ -551,6 +568,7 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
551568
Result.ASN = MSG_INVALID_IP;
552569
Result.AS = MSG_INVALID_IP;
553570
Result.Last_Seen = MSG_INVALID_IP;
571+
Result.Threat = MSG_INVALID_IP;
554572
return Result;
555573
}
556574

@@ -576,6 +594,7 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
576594
Result.ASN = MSG_MISSING_FILE;
577595
Result.AS = MSG_MISSING_FILE;
578596
Result.Last_Seen = MSG_MISSING_FILE;
597+
Result.Threat = MSG_MISSING_FILE;
579598
return Result;
580599
}
581600
}
@@ -623,6 +642,7 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
623642
Result.ASN = MSG_IPV6_UNSUPPORTED;
624643
Result.AS = MSG_IPV6_UNSUPPORTED;
625644
Result.Last_Seen = MSG_IPV6_UNSUPPORTED;
645+
Result.Threat = MSG_IPV6_UNSUPPORTED;
626646
return Result;
627647
}
628648
MAX_IP_RANGE = MAX_IPV6_RANGE;
@@ -673,6 +693,7 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
673693
String ASN = MSG_NOT_SUPPORTED;
674694
String AS = MSG_NOT_SUPPORTED;
675695
String Last_Seen = MSG_NOT_SUPPORTED;
696+
String Threat = MSG_NOT_SUPPORTED;
676697

677698
int FirstCol = 4; // IP From is 4 bytes
678699
if (IPType == 6) { // IPv6
@@ -768,6 +789,13 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
768789
}
769790
}
770791

792+
if (THREAT_ENABLED) {
793+
if (Mode == Modes.ALL || Mode == Modes.THREAT) {
794+
// Threat = ReadStr(Read32(RowOffset + THREAT_POSITION_OFFSET, Buf, RF).longValue(), RF);
795+
Threat = ReadStr(Read32_Row(Row, THREAT_POSITION_OFFSET).longValue(), DataBuf, RF);
796+
}
797+
}
798+
771799
if (Country_Short.equals("-") || Proxy_Type.equals("-")) {
772800
Is_Proxy = 0;
773801
}
@@ -792,6 +820,7 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
792820
Result.ASN = ASN;
793821
Result.AS = AS;
794822
Result.Last_Seen = Last_Seen;
823+
Result.Threat = Threat;
795824
return Result;
796825
}
797826
else {
@@ -815,6 +844,7 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
815844
Result.ASN = MSG_INVALID_IP;
816845
Result.AS = MSG_INVALID_IP;
817846
Result.Last_Seen = MSG_INVALID_IP;
847+
Result.Threat = MSG_INVALID_IP;
818848
return Result;
819849
}
820850
catch(IOException Ex) {

com/ip2proxy/ProxyResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ProxyResult {
1313
public String ASN;
1414
public String AS;
1515
public String Last_Seen;
16+
public String Threat;
1617

1718
ProxyResult() {
1819

0 commit comments

Comments
 (0)