Skip to content

Commit 2613887

Browse files
committed
Added support for PX9 to PX10 packages
1 parent 6eeca7d commit 2613887

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# IP2Proxy Node.js Module
22

3-
This module 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 module 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
@@ -23,30 +23,31 @@ Below are the methods supported in this class.
2323
|---|---|
2424
|Open|Open the IP2Proxy BIN data for lookup.|
2525
|Close|Close and clean up the file pointer.|
26-
|getPackageVersion|Get the package version (1 to 8 for PX1 to PX8 respectively).|
26+
|getPackageVersion|Get the package version (1 to 10 for PX1 to PX10 respectively).|
2727
|getModuleVersion|Get the module version.|
2828
|getDatabaseVersion|Get the database version.|
2929
|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>|
3030
|getAll|Return the proxy information in an object.|
31-
|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|
31+
|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|
3232
|getCountryShort|Return the ISO3166-1 country code (2-digits) of the proxy.|
3333
|getCountryLong|Return the ISO3166-1 country name of the proxy.|
3434
|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|
3535
|getCity|Return the city name of the proxy.|
3636
|getISP|Return the ISP name of the proxy.|
3737
|getDomain|Return the domain name of the proxy.|
38-
|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.|
38+
|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.|
3939
|getASN|Return the autonomous system number of the proxy.|
4040
|getAS|Return the autonomous system name of the proxy.|
4141
|getLastSeen|Return the number of days that the proxy was last seen.|
42+
|getThreat|Return the threat type of the proxy.|
4243

4344
## Usage
4445

4546
```javascript
4647

4748
var ip2proxy = require("ip2proxy-nodejs");
4849

49-
if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN") == 0) {
50+
if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.BIN") == 0) {
5051
ip = '199.83.103.79';
5152

5253
console.log("GetModuleVersion: " + ip2proxy.getModuleVersion());
@@ -66,6 +67,7 @@ if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGET
6667
console.log("ASN: " + ip2proxy.getASN(ip));
6768
console.log("AS: " + ip2proxy.getAS(ip));
6869
console.log("LastSeen: " + ip2proxy.getLastSeen(ip));
70+
console.log("Threat: " + ip2proxy.getThreat(ip));
6971

7072
// function for all fields
7173
var all = ip2proxy.getAll(ip);
@@ -81,6 +83,7 @@ if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGET
8183
console.log("ASN: " + all.ASN);
8284
console.log("AS: " + all.AS);
8385
console.log("LastSeen: " + all.Last_Seen);
86+
console.log("Threat: " + all.Threat);
8487
}
8588
else {
8689
console.log("Error reading BIN file.");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ip2proxy-nodejs",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "IP2Proxy proxy detection component",
55
"keywords": [
66
"vpn-detection",

src/ip2proxy.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var bigInt = require("big-integer");
44

55
var fd;
66

7-
var version = "2.2.0";
7+
var version = "2.3.0";
88
var binfile = "";
99
var IPv4ColumnSize = 0;
1010
var IPv6ColumnSize = 0;
@@ -16,17 +16,17 @@ var maxindex = 65536;
1616
var IndexArrayIPv4 = Array(maxindex);
1717
var IndexArrayIPv6 = Array(maxindex);
1818

19-
var country_pos = [0, 2, 3, 3, 3, 3, 3, 3, 3];
20-
var region_pos = [0, 0, 0, 4, 4, 4, 4, 4, 4];
21-
var city_pos = [0, 0, 0, 5, 5, 5, 5, 5, 5];
22-
var isp_pos = [0, 0, 0, 0, 6, 6, 6, 6, 6];
23-
var proxytype_pos = [0, 0, 2, 2, 2, 2, 2, 2, 2];
24-
var domain_pos = [0, 0, 0, 0, 0, 7, 7, 7, 7];
25-
var usagetype_pos = [0, 0, 0, 0, 0, 0, 8, 8, 8];
26-
var asn_pos = [0, 0, 0, 0, 0, 0, 0, 9, 9];
27-
var as_pos = [0, 0, 0, 0, 0, 0, 0, 10, 10];
28-
var lastseen_pos = [0, 0, 0, 0, 0, 0, 0, 0, 11];
29-
19+
var country_pos = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3];
20+
var region_pos = [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4];
21+
var city_pos = [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5];
22+
var isp_pos = [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6];
23+
var proxytype_pos = [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2];
24+
var domain_pos = [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7];
25+
var usagetype_pos = [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8];
26+
var asn_pos = [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9];
27+
var as_pos = [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10];
28+
var lastseen_pos = [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11];
29+
var threat_pos = [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12];
3030

3131
var country_pos_offset = 0;
3232
var region_pos_offset = 0;
@@ -38,6 +38,7 @@ var usagetype_pos_offset = 0;
3838
var asn_pos_offset = 0;
3939
var as_pos_offset = 0;
4040
var lastseen_pos_offset = 0;
41+
var threat_pos_offset = 0;
4142

4243
var country_enabled = 0;
4344
var region_enabled = 0;
@@ -49,6 +50,7 @@ var usagetype_enabled = 0;
4950
var asn_enabled = 0;
5051
var as_enabled = 0;
5152
var lastseen_enabled = 0;
53+
var threat_enabled = 0;
5254

5355
var MAX_IPV4_RANGE = bigInt(4294967295);
5456
var MAX_IPV6_RANGE = bigInt("340282366920938463463374607431768211455");
@@ -85,6 +87,7 @@ var modes = {
8587
"ASN": 10,
8688
"AS": 11,
8789
"LAST_SEEN": 12,
90+
"THREAT": 13,
8891
"ALL": 100
8992
};
9093

@@ -263,6 +266,7 @@ function loadbin() {
263266
// asn_pos_offset = (asn_pos[dbt] != 0) ? (asn_pos[dbt] - 1) << 2 : 0;
264267
// as_pos_offset = (as_pos[dbt] != 0) ? (as_pos[dbt] - 1) << 2 : 0;
265268
// lastseen_pos_offset = (lastseen_pos[dbt] != 0) ? (lastseen_pos[dbt] - 1) << 2 : 0;
269+
// threat_pos_offset = (threat_pos[dbt] != 0) ? (threat_pos[dbt] - 1) << 2 : 0;
266270

267271
// slightly different offset for reading by row
268272
country_pos_offset = (country_pos[dbt] != 0) ? (country_pos[dbt] - 2) << 2 : 0;
@@ -275,6 +279,7 @@ function loadbin() {
275279
asn_pos_offset = (asn_pos[dbt] != 0) ? (asn_pos[dbt] - 2) << 2 : 0;
276280
as_pos_offset = (as_pos[dbt] != 0) ? (as_pos[dbt] - 2) << 2 : 0;
277281
lastseen_pos_offset = (lastseen_pos[dbt] != 0) ? (lastseen_pos[dbt] - 2) << 2 : 0;
282+
threat_pos_offset = (threat_pos[dbt] != 0) ? (threat_pos[dbt] - 2) << 2 : 0;
278283

279284
country_enabled = (country_pos[dbt] != 0) ? 1 : 0;
280285
region_enabled = (region_pos[dbt] != 0) ? 1 : 0;
@@ -286,6 +291,7 @@ function loadbin() {
286291
asn_enabled = (asn_pos[dbt] != 0) ? 1 : 0;
287292
as_enabled = (as_pos[dbt] != 0) ? 1 : 0;
288293
lastseen_enabled = (lastseen_pos[dbt] != 0) ? 1 : 0;
294+
threat_enabled = (threat_pos[dbt] != 0) ? 1 : 0;
289295

290296
var pointer = mydb._IndexBaseAddr;
291297

@@ -510,6 +516,12 @@ function proxyquery_data(myIP, iptype, data, mode) {
510516
data.Last_Seen = readstr(read32_row(lastseen_pos_offset, row));
511517
}
512518
}
519+
if (threat_enabled) {
520+
if (mode == modes.ALL || mode == modes.THREAT) {
521+
// data.Threat = readstr(read32(rowoffset + threat_pos_offset));
522+
data.Threat = readstr(read32_row(threat_pos_offset, row));
523+
}
524+
}
513525

514526
if (data.Country_Short == "-" || data.Proxy_Type == "-") {
515527
data.Is_Proxy = 0;
@@ -551,7 +563,8 @@ function proxyquery(myIP, mode) {
551563
"Usage_Type": "?",
552564
"ASN": "?",
553565
"AS": "?",
554-
"Last_Seen": "?"
566+
"Last_Seen": "?",
567+
"Threat": "?"
555568
};
556569

557570
if (/^[:0]+:F{4}:(\d+\.){3}\d+$/i.test(myIP)) {
@@ -676,6 +689,12 @@ exports.getLastSeen = function getLastSeen(myIP) {
676689
return data.Last_Seen;
677690
}
678691

692+
// Returns a string for the threat
693+
exports.getThreat = function getThreat(myIP) {
694+
data = proxyquery(myIP, modes.THREAT);
695+
return data.Threat;
696+
}
697+
679698
// Returns all results
680699
exports.getAll = function getAll(myIP) {
681700
data = proxyquery(myIP, modes.ALL);

src/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// var ip2proxy = require("./ip2proxy.js");
22
var ip2proxy = require("ip2proxy-nodejs");
33

4-
ip2proxy.Open("PX8.BIN");
4+
ip2proxy.Open("PX10.BIN");
55

66
testip = ['8.8.8.8', '199.83.103.79'];
77

0 commit comments

Comments
 (0)