Skip to content

Commit 9c92099

Browse files
committed
Added support for PX5 to PX8 packages
1 parent 585e345 commit 9c92099

File tree

5 files changed

+129
-23
lines changed

5 files changed

+129
-23
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: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# IP2Proxy Node.js Module
22

3-
This module 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 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
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

99
## Installation
@@ -23,25 +23,30 @@ 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 4 for PX1 to PX4 respectively).|
26+
|getPackageVersion|Get the package version (1 to 8 for PX1 to PX8 respectively).|
2727
|getModuleVersion|Get the module version.|
2828
|getDatabaseVersion|Get the database version.|
29-
|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>|
29+
|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/databases/px4-ip-proxytype-country-region-city-isp" 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/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" 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.|
37+
|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.|
39+
|getASN|Return the autonomous system number of the proxy.|
40+
|getAS|Return the autonomous system name of the proxy.|
41+
|getLastSeen|Return the number of days that the proxy was last seen.|
3742

3843
## Usage
3944

4045
```javascript
4146

4247
var ip2proxy = require("ip2proxy-nodejs");
4348

44-
if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.BIN") == 0) {
49+
if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN") == 0) {
4550
ip = '199.83.103.79';
4651

4752
console.log("GetModuleVersion: " + ip2proxy.getModuleVersion());
@@ -56,7 +61,12 @@ if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.BIN") == 0) {
5661
console.log("Region: " + ip2proxy.getRegion(ip));
5762
console.log("City: " + ip2proxy.getCity(ip));
5863
console.log("ISP: " + ip2proxy.getISP(ip));
59-
64+
console.log("Domain: " + ip2proxy.getDomain(ip));
65+
console.log("UsageType: " + ip2proxy.getUsageType(ip));
66+
console.log("ASN: " + ip2proxy.getASN(ip));
67+
console.log("AS: " + ip2proxy.getAS(ip));
68+
console.log("LastSeen: " + ip2proxy.getLastSeen(ip));
69+
6070
// function for all fields
6171
var all = ip2proxy.getAll(ip);
6272
console.log("isProxy: " + all.Is_Proxy);
@@ -66,6 +76,11 @@ if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.BIN") == 0) {
6676
console.log("Region: " + all.Region);
6777
console.log("City: " + all.City);
6878
console.log("ISP: " + all.ISP);
79+
console.log("Domain: " + all.Domain);
80+
console.log("UsageType: " + all.Usage_Type);
81+
console.log("ASN: " + all.ASN);
82+
console.log("AS: " + all.AS);
83+
console.log("LastSeen: " + all.Last_Seen);
6984
}
7085
else {
7186
console.log("Error reading BIN file.");

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ip2proxy-nodejs",
3-
"version": "1.1.0",
3+
"version": "2.0.0",
44
"description": "IP2Proxy proxy detection component",
55
"keywords": [
66
"vpn-detection",
@@ -12,19 +12,19 @@
1212
"tor",
1313
"proxy"
1414
],
15-
"homepage": "http://www.ip2location.com/ip2proxy/developers/nodejs",
15+
"homepage": "https://www.ip2location.com/development-libraries/ip2proxy/nodejs",
1616
"author": {
1717
"name": "IP2Location.com",
1818
"email": "[email protected]",
19-
"url": "http://www.ip2location.com/"
19+
"url": "https://www.ip2location.com/"
2020
},
2121
"files": [
2222
"src/ip2proxy.js",
2323
"src/test.js",
2424
"./README.md"
2525
],
2626
"main": "src/ip2proxy.js",
27-
"license": "LGPL",
27+
"license": "MIT",
2828
"dependencies": {
2929
"big-integer": ">=1.6.8"
3030
},

src/ip2proxy.js

Lines changed: 101 additions & 10 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 = "1.1.0";
7+
var version = "2.0.0";
88
var binfile = "";
99
var IPv4ColumnSize = 0;
1010
var IPv6ColumnSize = 0;
@@ -16,23 +16,39 @@ var maxindex = 65536;
1616
var IndexArrayIPv4 = Array(maxindex);
1717
var IndexArrayIPv6 = Array(maxindex);
1818

19-
var country_pos = [0, 2, 3, 3, 3];
20-
var region_pos = [0, 0, 0, 4, 4];
21-
var city_pos = [0, 0, 0, 5, 5];
22-
var isp_pos = [0, 0, 0, 0, 6];
23-
var proxytype_pos = [0, 0, 2, 2, 2];
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+
2430

2531
var country_pos_offset = 0;
2632
var region_pos_offset = 0;
2733
var city_pos_offset = 0;
2834
var isp_pos_offset = 0;
2935
var proxytype_pos_offset = 0;
36+
var domain_pos_offset = 0;
37+
var usagetype_pos_offset = 0;
38+
var asn_pos_offset = 0;
39+
var as_pos_offset = 0;
40+
var lastseen_pos_offset = 0;
3041

3142
var country_enabled = 0;
3243
var region_enabled = 0;
3344
var city_enabled = 0;
3445
var isp_enabled = 0;
3546
var proxytype_enabled = 0;
47+
var domain_enabled = 0;
48+
var usagetype_enabled = 0;
49+
var asn_enabled = 0;
50+
var as_enabled = 0;
51+
var lastseen_enabled = 0;
3652

3753
var MAX_IPV4_RANGE = bigInt(4294967295);
3854
var MAX_IPV6_RANGE = bigInt("340282366920938463463374607431768211455");
@@ -59,6 +75,11 @@ var modes = {
5975
"ISP": 5,
6076
"PROXY_TYPE": 6,
6177
"IS_PROXY": 7,
78+
"DOMAIN": 8,
79+
"USAGE_TYPE": 9,
80+
"ASN": 10,
81+
"AS": 11,
82+
"LAST_SEEN": 12,
6283
"ALL": 100
6384
};
6485

@@ -215,12 +236,22 @@ function loadbin() {
215236
city_pos_offset = (city_pos[dbt] != 0) ? (city_pos[dbt] - 1) << 2 : 0;
216237
isp_pos_offset = (isp_pos[dbt] != 0) ? (isp_pos[dbt] - 1) << 2 : 0;
217238
proxytype_pos_offset = (proxytype_pos[dbt] != 0) ? (proxytype_pos[dbt] - 1) << 2 : 0;
239+
domain_pos_offset = (domain_pos[dbt] != 0) ? (domain_pos[dbt] - 1) << 2 : 0;
240+
usagetype_pos_offset = (usagetype_pos[dbt] != 0) ? (usagetype_pos[dbt] - 1) << 2 : 0;
241+
asn_pos_offset = (asn_pos[dbt] != 0) ? (asn_pos[dbt] - 1) << 2 : 0;
242+
as_pos_offset = (as_pos[dbt] != 0) ? (as_pos[dbt] - 1) << 2 : 0;
243+
lastseen_pos_offset = (lastseen_pos[dbt] != 0) ? (lastseen_pos[dbt] - 1) << 2 : 0;
218244

219245
country_enabled = (country_pos[dbt] != 0) ? 1 : 0;
220246
region_enabled = (region_pos[dbt] != 0) ? 1 : 0;
221247
city_enabled = (city_pos[dbt] != 0) ? 1 : 0;
222248
isp_enabled = (isp_pos[dbt] != 0) ? 1 : 0;
223249
proxytype_enabled = (proxytype_pos[dbt] != 0) ? 1 : 0;
250+
domain_enabled = (domain_pos[dbt] != 0) ? 1 : 0;
251+
usagetype_enabled = (usagetype_pos[dbt] != 0) ? 1 : 0;
252+
asn_enabled = (asn_pos[dbt] != 0) ? 1 : 0;
253+
as_enabled = (as_pos[dbt] != 0) ? 1 : 0;
254+
lastseen_enabled = (lastseen_pos[dbt] != 0) ? 1 : 0;
224255

225256
var pointer = mydb._IndexBaseAddr;
226257

@@ -387,12 +418,37 @@ function proxyquery_data(myIP, iptype, data, mode) {
387418
data.ISP = readstr(read32(rowoffset + isp_pos_offset));
388419
}
389420
}
421+
if (domain_enabled) {
422+
if (mode == modes.ALL || mode == modes.DOMAIN) {
423+
data.Domain = readstr(read32(rowoffset + domain_pos_offset));
424+
}
425+
}
426+
if (usagetype_enabled) {
427+
if (mode == modes.ALL || mode == modes.USAGE_TYPE) {
428+
data.Usage_Type = readstr(read32(rowoffset + usagetype_pos_offset));
429+
}
430+
}
431+
if (asn_enabled) {
432+
if (mode == modes.ALL || mode == modes.ASN) {
433+
data.ASN = readstr(read32(rowoffset + asn_pos_offset));
434+
}
435+
}
436+
if (as_enabled) {
437+
if (mode == modes.ALL || mode == modes.AS) {
438+
data.AS = readstr(read32(rowoffset + as_pos_offset));
439+
}
440+
}
441+
if (lastseen_enabled) {
442+
if (mode == modes.ALL || mode == modes.LAST_SEEN) {
443+
data.Last_Seen = readstr(read32(rowoffset + lastseen_pos_offset));
444+
}
445+
}
390446

391447
if (data.Country_Short == "-" || data.Proxy_Type == "-") {
392448
data.Is_Proxy = 0;
393449
}
394450
else {
395-
if (data.Proxy_Type == "DCH") {
451+
if ((data.Proxy_Type == "DCH") || (data.Proxy_Type == "SES")) {
396452
data.Is_Proxy = 2;
397453
}
398454
else {
@@ -423,7 +479,12 @@ function proxyquery(myIP, mode) {
423479
"Country_Long": "?",
424480
"Region": "?",
425481
"City": "?",
426-
"ISP": "?"
482+
"ISP": "?",
483+
"Domain": "?",
484+
"Usage_Type": "?",
485+
"ASN": "?",
486+
"AS": "?",
487+
"Last_Seen": "?"
427488
};
428489

429490
if (/^[:0]+:F{4}:(\d+\.){3}\d+$/i.test(myIP)) {
@@ -476,8 +537,8 @@ exports.getDatabaseVersion = function getDatabaseVersion() {
476537
exports.isProxy = function isProxy(myIP) {
477538
// -1 is error
478539
// 0 is not a proxy
479-
// 1 is proxy except DCH
480-
// 2 is proxy and DCH
540+
// 1 is proxy except DCH and SES
541+
// 2 is proxy and DCH or SES
481542
data = proxyquery(myIP, modes.IS_PROXY);
482543
return data.Is_Proxy;
483544
}
@@ -518,6 +579,36 @@ exports.getProxyType = function getProxyType(myIP) {
518579
return data.Proxy_Type;
519580
}
520581

582+
// Returns a string for the domain
583+
exports.getDomain = function getDomain(myIP) {
584+
data = proxyquery(myIP, modes.DOMAIN);
585+
return data.Domain;
586+
}
587+
588+
// Returns a string for the usage type
589+
exports.getUsageType = function getUsageType(myIP) {
590+
data = proxyquery(myIP, modes.USAGE_TYPE);
591+
return data.Usage_Type;
592+
}
593+
594+
// Returns a string for the ASN
595+
exports.getASN = function getASN(myIP) {
596+
data = proxyquery(myIP, modes.ASN);
597+
return data.ASN;
598+
}
599+
600+
// Returns a string for the AS
601+
exports.getAS = function getAS(myIP) {
602+
data = proxyquery(myIP, modes.AS);
603+
return data.AS;
604+
}
605+
606+
// Returns a string for the last seen
607+
exports.getLastSeen = function getLastSeen(myIP) {
608+
data = proxyquery(myIP, modes.LAST_SEEN);
609+
return data.Last_Seen;
610+
}
611+
521612
// Returns all results
522613
exports.getAll = function getAll(myIP) {
523614
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("PX4.BIN");
4+
ip2proxy.Open("PX8.BIN");
55

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

0 commit comments

Comments
 (0)