Skip to content

Commit 5b13ae8

Browse files
committed
Added support for PX5 to PX8 packages
1 parent 10e76f2 commit 5b13ae8

File tree

4 files changed

+190
-14
lines changed

4 files changed

+190
-14
lines changed

LICENSE.TXT

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) 2017 IP2Location.com
3+
Copyright (c) 2019 IP2Location.com
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: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# IP2Proxy Java Component
22

3-
This component allows user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits. 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 and search engine robots (SES). 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
6-
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/proxy-database
6+
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy
77

88
## Compilation
99

@@ -19,17 +19,22 @@ 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 4 for PX1 to PX4 respectively).|
22+
|GetPackageVersion|Get the package version (1 to 8 for PX1 to PX8 respectively).|
2323
|GetModuleVersion|Get the module version.|
2424
|GetDatabaseVersion|Get the database version.|
25-
|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</li></ul>|
25+
|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.|
2727
|GetProxyType|Return the proxy type. Please visit <a href="https://www.ip2location.com/databases/px4-ip-proxytype-country-region-city-isp" 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.|
33+
|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.|
35+
|GetASN|Return the autonomous system number of the proxy.|
36+
|GetAS|Return the autonomous system name of the proxy.|
37+
|GetLastSeen|Return the number of days that the proxy was last seen.|
3338

3439
## Usage
3540

@@ -57,10 +62,15 @@ public class Main {
5762
String Region;
5863
String City;
5964
String ISP;
65+
String Domain;
66+
String UsageType;
67+
String ASN;
68+
String AS;
69+
String LastSeen;
6070

6171
String IP = "221.121.146.0";
6272

63-
if (Proxy.Open("/usr/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN", IP2Proxy.IOModes.IP2PROXY_MEMORY_MAPPED) == 0) {
73+
if (Proxy.Open("/usr/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN", IP2Proxy.IOModes.IP2PROXY_MEMORY_MAPPED) == 0) {
6474
System.out.println("GetModuleVersion: " + Proxy.GetModuleVersion());
6575
System.out.println("GetPackageVersion: " + Proxy.GetPackageVersion());
6676
System.out.println("GetDatabaseVersion: " + Proxy.GetDatabaseVersion());
@@ -74,6 +84,11 @@ public class Main {
7484
System.out.println("Region: " + All.Region);
7585
System.out.println("City: " + All.City);
7686
System.out.println("ISP: " + All.ISP);
87+
System.out.println("Domain: " + All.Domain);
88+
System.out.println("Usage_Type: " + All.Usage_Type);
89+
System.out.println("ASN: " + All.ASN);
90+
System.out.println("AS: " + All.AS);
91+
System.out.println("Last_Seen: " + All.Last_Seen);
7792

7893
// reading individual fields
7994
IsProxy = Proxy.IsProxy(IP);
@@ -96,6 +111,21 @@ public class Main {
96111

97112
ISP = Proxy.GetISP(IP);
98113
System.out.println("ISP: " + ISP);
114+
115+
Domain = Proxy.GetDomain(IP);
116+
System.out.println("Domain: " + Domain);
117+
118+
UsageType = Proxy.GetUsageType(IP);
119+
System.out.println("UsageType: " + UsageType);
120+
121+
ASN = Proxy.GetASN(IP);
122+
System.out.println("ASN: " + ASN);
123+
124+
AS = Proxy.GetAS(IP);
125+
System.out.println("AS: " + AS);
126+
127+
LastSeen = Proxy.GetLastSeen(IP);
128+
System.out.println("LastSeen: " + LastSeen);
99129
}
100130
else {
101131
System.out.println("Error reading BIN file.");

com/ip2proxy/IP2Proxy.java

Lines changed: 149 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,24 @@ private enum Modes {
4141
ISP,
4242
PROXY_TYPE,
4343
IS_PROXY,
44+
DOMAIN,
45+
USAGE_TYPE,
46+
ASN,
47+
AS,
48+
LAST_SEEN,
4449
ALL;
4550
}
4651

47-
private static final int COUNTRY_POSITION[] = {0, 2, 3, 3, 3};
48-
private static final int REGION_POSITION[] = {0, 0, 0, 4, 4};
49-
private static final int CITY_POSITION[] = {0, 0, 0, 5, 5};
50-
private static final int ISP_POSITION[] = {0, 0, 0, 0, 6};
51-
private static final int PROXYTYPE_POSITION[] = {0, 0, 2, 2, 2};
52+
private static final int COUNTRY_POSITION[] = {0, 2, 3, 3, 3, 3, 3, 3, 3};
53+
private static final int REGION_POSITION[] = {0, 0, 0, 4, 4, 4, 4, 4, 4};
54+
private static final int CITY_POSITION[] = {0, 0, 0, 5, 5, 5, 5, 5, 5};
55+
private static final int ISP_POSITION[] = {0, 0, 0, 0, 6, 6, 6, 6, 6};
56+
private static final int PROXYTYPE_POSITION[] = {0, 0, 2, 2, 2, 2, 2, 2, 2};
57+
private static final int DOMAIN_POSITION[] = {0, 0, 0, 0, 0, 7, 7, 7, 7};
58+
private static final int USAGETYPE_POSITION[] = {0, 0, 0, 0, 0, 0, 8, 8, 8};
59+
private static final int ASN_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 9, 9};
60+
private static final int AS_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 10, 10};
61+
private static final int LASTSEEN_POSITION[] = {0, 0, 0, 0, 0, 0, 0, 0, 11};
5262

5363
private MappedByteBuffer _IPv4Buffer = null;
5464
private MappedByteBuffer _IPv6Buffer = null;
@@ -81,13 +91,24 @@ private enum Modes {
8191
private int CITY_POSITION_OFFSET;
8292
private int ISP_POSITION_OFFSET;
8393
private int PROXYTYPE_POSITION_OFFSET;
94+
private int DOMAIN_POSITION_OFFSET;
95+
private int USAGETYPE_POSITION_OFFSET;
96+
private int ASN_POSITION_OFFSET;
97+
private int AS_POSITION_OFFSET;
98+
private int LASTSEEN_POSITION_OFFSET;
99+
84100
private boolean COUNTRY_ENABLED;
85101
private boolean REGION_ENABLED;
86102
private boolean CITY_ENABLED;
87103
private boolean ISP_ENABLED;
88104
private boolean PROXYTYPE_ENABLED;
105+
private boolean DOMAIN_ENABLED;
106+
private boolean USAGETYPE_ENABLED;
107+
private boolean ASN_ENABLED;
108+
private boolean AS_ENABLED;
109+
private boolean LASTSEEN_ENABLED;
89110

90-
private static final String _ModuleVersion = "1.0.1";
111+
private static final String _ModuleVersion = "2.0.0";
91112

92113
public IP2Proxy() {
93114

@@ -125,7 +146,7 @@ public String GetDatabaseVersion() {
125146
/**
126147
* This function returns ans integer to state if it proxy.
127148
* @param IP IP Address you wish to query
128-
* @return -1 if error, 0 if not a proxy, 1 if proxy except DCH, 2 if proxy and DCH
149+
* @return -1 if error, 0 if not a proxy, 1 if proxy except DCH and SES, 2 if proxy and either DCH or SES
129150
*/
130151
public int IsProxy(String IP) throws IOException {
131152
return ProxyQuery(IP, Modes.IS_PROXY).Is_Proxy;
@@ -185,6 +206,51 @@ public String GetProxyType(String IP) throws IOException {
185206
return ProxyQuery(IP, Modes.PROXY_TYPE).Proxy_Type;
186207
}
187208

209+
/**
210+
* This function returns the domain.
211+
* @param IP IP Address you wish to query
212+
* @return Domain
213+
*/
214+
public String GetDomain(String IP) throws IOException {
215+
return ProxyQuery(IP, Modes.DOMAIN).Domain;
216+
}
217+
218+
/**
219+
* This function returns the usage type.
220+
* @param IP IP Address you wish to query
221+
* @return Proxy type
222+
*/
223+
public String GetUsageType(String IP) throws IOException {
224+
return ProxyQuery(IP, Modes.USAGE_TYPE).Usage_Type;
225+
}
226+
227+
/**
228+
* This function returns the Autonomous System Number.
229+
* @param IP IP Address you wish to query
230+
* @return Autonomous System Number
231+
*/
232+
public String GetASN(String IP) throws IOException {
233+
return ProxyQuery(IP, Modes.ASN).ASN;
234+
}
235+
236+
/**
237+
* This function returns the Autonomous System name.
238+
* @param IP IP Address you wish to query
239+
* @return Autonomous System name
240+
*/
241+
public String GetAS(String IP) throws IOException {
242+
return ProxyQuery(IP, Modes.AS).AS;
243+
}
244+
245+
/**
246+
* This function returns number of days the proxy was last seen.
247+
* @param IP IP Address you wish to query
248+
* @return Number of days last seen
249+
*/
250+
public String GetLastSeen(String IP) throws IOException {
251+
return ProxyQuery(IP, Modes.LAST_SEEN).Last_Seen;
252+
}
253+
188254
/**
189255
* This function returns proxy result.
190256
* @param IP IP Address you wish to query
@@ -305,12 +371,22 @@ private boolean LoadBIN() throws IOException {
305371
CITY_POSITION_OFFSET = (CITY_POSITION[_DBType] != 0) ? (CITY_POSITION[_DBType] - 1) << 2 : 0;
306372
ISP_POSITION_OFFSET = (ISP_POSITION[_DBType] != 0) ? (ISP_POSITION[_DBType] - 1) << 2 : 0;
307373
PROXYTYPE_POSITION_OFFSET = (PROXYTYPE_POSITION[_DBType] != 0) ? (PROXYTYPE_POSITION[_DBType] - 1) << 2 : 0;
374+
DOMAIN_POSITION_OFFSET = (DOMAIN_POSITION[_DBType] != 0) ? (DOMAIN_POSITION[_DBType] - 1) << 2 : 0;
375+
USAGETYPE_POSITION_OFFSET = (USAGETYPE_POSITION[_DBType] != 0) ? (USAGETYPE_POSITION[_DBType] - 1) << 2 : 0;
376+
ASN_POSITION_OFFSET = (ASN_POSITION[_DBType] != 0) ? (ASN_POSITION[_DBType] - 1) << 2 : 0;
377+
AS_POSITION_OFFSET = (AS_POSITION[_DBType] != 0) ? (AS_POSITION[_DBType] - 1) << 2 : 0;
378+
LASTSEEN_POSITION_OFFSET = (LASTSEEN_POSITION[_DBType] != 0) ? (LASTSEEN_POSITION[_DBType] - 1) << 2 : 0;
308379

309380
COUNTRY_ENABLED = (COUNTRY_POSITION[_DBType] != 0) ? true : false;
310381
REGION_ENABLED = (REGION_POSITION[_DBType] != 0) ? true : false;
311382
CITY_ENABLED = (CITY_POSITION[_DBType] != 0) ? true : false;
312383
ISP_ENABLED = (ISP_POSITION[_DBType] != 0) ? true : false;
313384
PROXYTYPE_ENABLED = (PROXYTYPE_POSITION[_DBType] != 0) ? true : false;
385+
DOMAIN_ENABLED = (DOMAIN_POSITION[_DBType] != 0) ? true : false;
386+
USAGETYPE_ENABLED = (USAGETYPE_POSITION[_DBType] != 0) ? true : false;
387+
ASN_ENABLED = (ASN_POSITION[_DBType] != 0) ? true : false;
388+
AS_ENABLED = (AS_POSITION[_DBType] != 0) ? true : false;
389+
LASTSEEN_ENABLED = (LASTSEEN_POSITION[_DBType] != 0) ? true : false;
314390

315391
final MappedByteBuffer _IndexBuffer = InChannel.map(FileChannel.MapMode.READ_ONLY, _IndexBaseAddr - 1, _BaseAddr - _IndexBaseAddr); // reading indexes
316392
_IndexBuffer.order(ByteOrder.LITTLE_ENDIAN);
@@ -406,6 +482,11 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
406482
Result.Region = MSG_INVALID_IP;
407483
Result.City = MSG_INVALID_IP;
408484
Result.ISP = MSG_INVALID_IP;
485+
Result.Domain = MSG_INVALID_IP;
486+
Result.Usage_Type = MSG_INVALID_IP;
487+
Result.ASN = MSG_INVALID_IP;
488+
Result.AS = MSG_INVALID_IP;
489+
Result.Last_Seen = MSG_INVALID_IP;
409490
return Result;
410491
}
411492

@@ -443,6 +524,11 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
443524
Result.Region = MSG_INVALID_IP;
444525
Result.City = MSG_INVALID_IP;
445526
Result.ISP = MSG_INVALID_IP;
527+
Result.Domain = MSG_INVALID_IP;
528+
Result.Usage_Type = MSG_INVALID_IP;
529+
Result.ASN = MSG_INVALID_IP;
530+
Result.AS = MSG_INVALID_IP;
531+
Result.Last_Seen = MSG_INVALID_IP;
446532
return Result;
447533
}
448534

@@ -463,6 +549,11 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
463549
Result.Region = MSG_MISSING_FILE;
464550
Result.City = MSG_MISSING_FILE;
465551
Result.ISP = MSG_MISSING_FILE;
552+
Result.Domain = MSG_MISSING_FILE;
553+
Result.Usage_Type = MSG_MISSING_FILE;
554+
Result.ASN = MSG_MISSING_FILE;
555+
Result.AS = MSG_MISSING_FILE;
556+
Result.Last_Seen = MSG_MISSING_FILE;
466557
return Result;
467558
}
468559
}
@@ -503,6 +594,11 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
503594
Result.Region = MSG_IPV6_UNSUPPORTED;
504595
Result.City = MSG_IPV6_UNSUPPORTED;
505596
Result.ISP = MSG_IPV6_UNSUPPORTED;
597+
Result.Domain = MSG_IPV6_UNSUPPORTED;
598+
Result.Usage_Type = MSG_IPV6_UNSUPPORTED;
599+
Result.ASN = MSG_IPV6_UNSUPPORTED;
600+
Result.AS = MSG_IPV6_UNSUPPORTED;
601+
Result.Last_Seen = MSG_IPV6_UNSUPPORTED;
506602
return Result;
507603
}
508604
MAX_IP_RANGE = MAX_IPV6_RANGE;
@@ -546,6 +642,11 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
546642
String Region = MSG_NOT_SUPPORTED;
547643
String City = MSG_NOT_SUPPORTED;
548644
String ISP = MSG_NOT_SUPPORTED;
645+
String Domain = MSG_NOT_SUPPORTED;
646+
String Usage_Type = MSG_NOT_SUPPORTED;
647+
String ASN = MSG_NOT_SUPPORTED;
648+
String AS = MSG_NOT_SUPPORTED;
649+
String Last_Seen = MSG_NOT_SUPPORTED;
549650

550651
if (IPType == 6) { // IPv6
551652
RowOffset = RowOffset + 12; // coz below is assuming all columns are 4 bytes, so got 12 left to go to make 16 bytes total
@@ -587,11 +688,41 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
587688
}
588689
}
589690

691+
if (DOMAIN_ENABLED) {
692+
if (Mode == Modes.ALL || Mode == Modes.DOMAIN) {
693+
Domain = ReadStr(Read32(RowOffset + DOMAIN_POSITION_OFFSET, Buf, RF).longValue(), RF);
694+
}
695+
}
696+
697+
if (USAGETYPE_ENABLED) {
698+
if (Mode == Modes.ALL || Mode == Modes.USAGE_TYPE) {
699+
Usage_Type = ReadStr(Read32(RowOffset + USAGETYPE_POSITION_OFFSET, Buf, RF).longValue(), RF);
700+
}
701+
}
702+
703+
if (ASN_ENABLED) {
704+
if (Mode == Modes.ALL || Mode == Modes.ASN) {
705+
ASN = ReadStr(Read32(RowOffset + ASN_POSITION_OFFSET, Buf, RF).longValue(), RF);
706+
}
707+
}
708+
709+
if (AS_ENABLED) {
710+
if (Mode == Modes.ALL || Mode == Modes.AS) {
711+
AS = ReadStr(Read32(RowOffset + AS_POSITION_OFFSET, Buf, RF).longValue(), RF);
712+
}
713+
}
714+
715+
if (LASTSEEN_ENABLED) {
716+
if (Mode == Modes.ALL || Mode == Modes.LAST_SEEN) {
717+
Last_Seen = ReadStr(Read32(RowOffset + LASTSEEN_POSITION_OFFSET, Buf, RF).longValue(), RF);
718+
}
719+
}
720+
590721
if (Country_Short.equals("-") || Proxy_Type.equals("-")) {
591722
Is_Proxy = 0;
592723
}
593724
else {
594-
if (Proxy_Type.equals("DCH")) {
725+
if (Proxy_Type.equals("DCH") || Proxy_Type.equals("SES")) {
595726
Is_Proxy = 2;
596727
}
597728
else {
@@ -606,6 +737,11 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
606737
Result.Region = Region;
607738
Result.City = City;
608739
Result.ISP = ISP;
740+
Result.Domain = Domain;
741+
Result.Usage_Type = Usage_Type;
742+
Result.ASN = ASN;
743+
Result.AS = AS;
744+
Result.Last_Seen = Last_Seen;
609745
return Result;
610746
}
611747
else {
@@ -624,6 +760,11 @@ public ProxyResult ProxyQuery(String IPAddress, Modes Mode) throws IOException {
624760
Result.Region = MSG_INVALID_IP;
625761
Result.City = MSG_INVALID_IP;
626762
Result.ISP = MSG_INVALID_IP;
763+
Result.Domain = MSG_INVALID_IP;
764+
Result.Usage_Type = MSG_INVALID_IP;
765+
Result.ASN = MSG_INVALID_IP;
766+
Result.AS = MSG_INVALID_IP;
767+
Result.Last_Seen = MSG_INVALID_IP;
627768
return Result;
628769
}
629770
catch(IOException Ex) {

com/ip2proxy/ProxyResult.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public class ProxyResult {
88
public String Region;
99
public String City;
1010
public String ISP;
11+
public String Domain;
12+
public String Usage_Type;
13+
public String ASN;
14+
public String AS;
15+
public String Last_Seen;
1116

1217
ProxyResult() {
1318

0 commit comments

Comments
 (0)