Skip to content

Commit 1d9a2c9

Browse files
committed
Added support for fraud score
1 parent e16a47b commit 1d9a2c9

File tree

6 files changed

+120
-60
lines changed

6 files changed

+120
-60
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 - 2024 IP2Location.com
3+
Copyright (c) 2017 - 2025 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# IP2Proxy Node.js Module
55

6-
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), residential proxies (RES), consumer privacy networks (CPN), and enterprise private networks (EPN). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
6+
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), residential proxies (RES), consumer privacy networks (CPN), enterprise private networks (EPN) and fraud score. It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
77

88
* Free IP2Proxy BIN Data: https://lite.ip2location.com
99
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy

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": "4.3.2",
3+
"version": "4.4.0",
44
"description": "IP2Proxy proxy detection component",
55
"keywords": [
66
"vpn-detection",

src/ip2proxy.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export class IP2Proxy {
176176
lastSeen: string;
177177
threat: string;
178178
provider: string;
179+
fraudScore: string;
179180
};
180181
/**
181182
* Performs validations and returns proxy data asynchronously.
@@ -201,6 +202,7 @@ export class IP2Proxy {
201202
lastSeen: string;
202203
threat: string;
203204
provider: string;
205+
fraudScore: string;
204206
}>;
205207
/**
206208
* Returns the module version.
@@ -416,6 +418,20 @@ export class IP2Proxy {
416418
* @returns The promise of the name of the VPN provider.
417419
*/
418420
getProviderAsync(myIP: string): Promise<string>;
421+
/**
422+
* Returns the fraud score.
423+
*
424+
* @param myIP The IP address to query.
425+
* @returns The fraud score.
426+
*/
427+
getFraudScore(myIP: string): string;
428+
/**
429+
* Returns the fraud score asynchronously.
430+
*
431+
* @param myIP The IP address to query.
432+
* @returns The promise of the fraud score.
433+
*/
434+
getFraudScoreAsync(myIP: string): Promise<string>;
419435
/**
420436
* Returns all fields.
421437
*
@@ -439,6 +455,7 @@ export class IP2Proxy {
439455
lastSeen: string;
440456
threat: string;
441457
provider: string;
458+
fraudScore: string;
442459
};
443460
/**
444461
* Returns all fields asynchronously.
@@ -463,6 +480,7 @@ export class IP2Proxy {
463480
lastSeen: string;
464481
threat: string;
465482
provider: string;
483+
fraudScore: string;
466484
}>;
467485
#private;
468486
}

src/ip2proxy.js

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ const fsp = fs.promises;
44
const https = require("https");
55

66
// For BIN queries
7-
const VERSION = "4.3.2";
7+
const VERSION = "4.4.0";
88
const MAX_INDEX = 65536;
9-
const COUNTRY_POSITION = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
10-
const REGION_POSITION = [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4];
11-
const CITY_POSITION = [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5];
12-
const ISP_POSITION = [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6];
13-
const PROXY_TYPE_POSITION = [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2];
14-
const DOMAIN_POSITION = [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7];
15-
const USAGE_TYPE_POSITION = [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8];
16-
const ASN_POSITION = [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9];
17-
const AS_POSITION = [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10];
18-
const LAST_SEEN_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11];
19-
const THREAT_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12];
20-
const PROVIDER_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13];
9+
const COUNTRY_POSITION = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
10+
const REGION_POSITION = [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4];
11+
const CITY_POSITION = [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];
12+
const ISP_POSITION = [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6];
13+
const PROXY_TYPE_POSITION = [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2];
14+
const DOMAIN_POSITION = [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7];
15+
const USAGE_TYPE_POSITION = [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8];
16+
const ASN_POSITION = [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9];
17+
const AS_POSITION = [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10];
18+
const LAST_SEEN_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 11];
19+
const THREAT_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12];
20+
const PROVIDER_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 13];
21+
const FRAUD_SCORE_POSITION = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14];
2122
const MAX_IPV4_RANGE = BigInt(4294967295);
2223
const MAX_IPV6_RANGE = BigInt("340282366920938463463374607431768211455");
2324
const FROM_6TO4 = BigInt("42545680458834377588178886921629466624");
@@ -42,6 +43,7 @@ const MODES = {
4243
LAST_SEEN: 12,
4344
THREAT: 13,
4445
PROVIDER: 14,
46+
FRAUD_SCORE: 15,
4547
ALL: 100,
4648
};
4749
const MSG_NOT_SUPPORTED = "NOT SUPPORTED";
@@ -96,6 +98,7 @@ class IP2Proxy {
9698
#lastSeenPositionOffset = 0;
9799
#threatPositionOffset = 0;
98100
#providerPositionOffset = 0;
101+
#fraudScorePositionOffset = 0;
99102

100103
#countryEnabled = 0;
101104
#regionEnabled = 0;
@@ -109,6 +112,7 @@ class IP2Proxy {
109112
#lastSeenEnabled = 0;
110113
#threatEnabled = 0;
111114
#providerEnabled = 0;
115+
#fraudScoreEnabled = 0;
112116

113117
#myDB = {
114118
dbType: 0,
@@ -344,6 +348,10 @@ class IP2Proxy {
344348
THREAT_POSITION[dbt] != 0 ? (THREAT_POSITION[dbt] - 2) << 2 : 0;
345349
this.#providerPositionOffset =
346350
PROVIDER_POSITION[dbt] != 0 ? (PROVIDER_POSITION[dbt] - 2) << 2 : 0;
351+
this.#fraudScorePositionOffset =
352+
FRAUD_SCORE_POSITION[dbt] != 0
353+
? (FRAUD_SCORE_POSITION[dbt] - 2) << 2
354+
: 0;
347355

348356
this.#countryEnabled = COUNTRY_POSITION[dbt] != 0 ? 1 : 0;
349357
this.#regionEnabled = REGION_POSITION[dbt] != 0 ? 1 : 0;
@@ -357,6 +365,7 @@ class IP2Proxy {
357365
this.#lastSeenEnabled = LAST_SEEN_POSITION[dbt] != 0 ? 1 : 0;
358366
this.#threatEnabled = THREAT_POSITION[dbt] != 0 ? 1 : 0;
359367
this.#providerEnabled = PROVIDER_POSITION[dbt] != 0 ? 1 : 0;
368+
this.#fraudScoreEnabled = FRAUD_SCORE_POSITION[dbt] != 0 ? 1 : 0;
360369

361370
if (this.#myDB.indexed == 1) {
362371
len = MAX_INDEX;
@@ -471,6 +480,10 @@ class IP2Proxy {
471480
THREAT_POSITION[dbt] != 0 ? (THREAT_POSITION[dbt] - 2) << 2 : 0;
472481
this.#providerPositionOffset =
473482
PROVIDER_POSITION[dbt] != 0 ? (PROVIDER_POSITION[dbt] - 2) << 2 : 0;
483+
this.#fraudScorePositionOffset =
484+
FRAUD_SCORE_POSITION[dbt] != 0
485+
? (FRAUD_SCORE_POSITION[dbt] - 2) << 2
486+
: 0;
474487

475488
this.#countryEnabled = COUNTRY_POSITION[dbt] != 0 ? 1 : 0;
476489
this.#regionEnabled = REGION_POSITION[dbt] != 0 ? 1 : 0;
@@ -484,6 +497,7 @@ class IP2Proxy {
484497
this.#lastSeenEnabled = LAST_SEEN_POSITION[dbt] != 0 ? 1 : 0;
485498
this.#threatEnabled = THREAT_POSITION[dbt] != 0 ? 1 : 0;
486499
this.#providerEnabled = PROVIDER_POSITION[dbt] != 0 ? 1 : 0;
500+
this.#fraudScoreEnabled = FRAUD_SCORE_POSITION[dbt] != 0 ? 1 : 0;
487501

488502
if (this.#myDB.indexed == 1) {
489503
len = MAX_INDEX;
@@ -809,6 +823,13 @@ class IP2Proxy {
809823
);
810824
}
811825
}
826+
if (this.#fraudScoreEnabled) {
827+
if (mode == MODES.ALL || mode == MODES.FRAUD_SCORE) {
828+
data.fraudScore = this.readStr(
829+
this.read32Row(this.#fraudScorePositionOffset, row)
830+
);
831+
}
832+
}
812833

813834
if (data.countryShort == "-" || data.proxyType == "-") {
814835
data.isProxy = 0;
@@ -1038,6 +1059,13 @@ class IP2Proxy {
10381059
);
10391060
}
10401061
}
1062+
if (this.#fraudScoreEnabled) {
1063+
if (mode == MODES.ALL || mode == MODES.FRAUD_SCORE) {
1064+
data.fraudScore = await this.readStrAsync(
1065+
this.read32Row(this.#fraudScorePositionOffset, row)
1066+
);
1067+
}
1068+
}
10411069

10421070
if (data.countryShort == "-" || data.proxyType == "-") {
10431071
data.isProxy = 0;
@@ -1079,6 +1107,7 @@ class IP2Proxy {
10791107
lastSeen: "?",
10801108
threat: "?",
10811109
provider: "?",
1110+
fraudScore: "?",
10821111
};
10831112

10841113
if (REGEX_IPV4_1_MATCH.test(myIP)) {
@@ -1127,6 +1156,7 @@ class IP2Proxy {
11271156
lastSeen: "?",
11281157
threat: "?",
11291158
provider: "?",
1159+
fraudScore: "?",
11301160
};
11311161

11321162
if (REGEX_IPV4_1_MATCH.test(myIP)) {
@@ -1354,6 +1384,18 @@ class IP2Proxy {
13541384
return data.provider;
13551385
}
13561386

1387+
// Return a string for the fraud score
1388+
getFraudScore(myIP) {
1389+
let data = this.proxyQuery(myIP, MODES.FRAUD_SCORE);
1390+
return data.fraudScore;
1391+
}
1392+
1393+
// Return a string for the fraud score async
1394+
async getFraudScoreAsync(myIP) {
1395+
let data = await this.proxyQueryAsync(myIP, MODES.FRAUD_SCORE);
1396+
return data.fraudScore;
1397+
}
1398+
13571399
// Return all results
13581400
getAll(myIP) {
13591401
let data = this.proxyQuery(myIP, MODES.ALL);

src/test.js

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
const {IP2Proxy, IP2ProxyWebService} = require("ip2proxy-nodejs");
2-
// const {IP2Proxy, IP2ProxyWebService} = require("./ip2proxy.js");
3-
4-
let ip2proxy = new IP2Proxy();
5-
6-
ip2proxy.open('PX11.BIN');
7-
8-
console.log("Module version " + ip2proxy.getModuleVersion());
9-
console.log("Package version " + ip2proxy.getPackageVersion());
10-
console.log("Database version " + ip2proxy.getDatabaseVersion());
11-
12-
testip = ['8.8.8.8', '199.83.103.79', '199.83.103.279'];
13-
14-
for (let x = 0; x < testip.length; x++) {
15-
result = ip2proxy.getAll(testip[x]);
16-
for (let key in result) {
17-
console.log(key + ": " + result[key]);
18-
}
19-
console.log("--------------------------------------------------------------");
20-
}
21-
22-
ip2proxy.close();
23-
24-
let ws = new IP2ProxyWebService();
25-
26-
let ip = "8.8.8.8";
27-
let apiKey = "YOUR_API_KEY";
28-
let apiPackage = "PX11";
29-
let useSSL = true;
30-
31-
ws.open(apiKey, apiPackage, useSSL);
32-
33-
ws.lookup(ip, (err, data) => {
34-
if (!err) {
35-
console.log(data);
36-
37-
ws.getCredit((err, data) => {
38-
if (!err) {
39-
console.log(data);
40-
}
41-
});
42-
}
43-
});
44-
1+
const {IP2Proxy, IP2ProxyWebService} = require("ip2proxy-nodejs");
2+
// const {IP2Proxy, IP2ProxyWebService} = require("./ip2proxy.js");
3+
4+
let ip2proxy = new IP2Proxy();
5+
6+
ip2proxy.open('PX12.BIN');
7+
8+
console.log("Module version " + ip2proxy.getModuleVersion());
9+
console.log("Package version " + ip2proxy.getPackageVersion());
10+
console.log("Database version " + ip2proxy.getDatabaseVersion());
11+
12+
testip = ['8.8.8.8', '199.83.103.79', '199.83.103.279'];
13+
14+
for (let x = 0; x < testip.length; x++) {
15+
result = ip2proxy.getAll(testip[x]);
16+
for (let key in result) {
17+
console.log(key + ": " + result[key]);
18+
}
19+
console.log("--------------------------------------------------------------");
20+
}
21+
22+
ip2proxy.close();
23+
24+
let ws = new IP2ProxyWebService();
25+
26+
let ip = "8.8.8.8";
27+
let apiKey = "YOUR_API_KEY";
28+
let apiPackage = "PX12";
29+
let useSSL = true;
30+
31+
ws.open(apiKey, apiPackage, useSSL);
32+
33+
ws.lookup(ip, (err, data) => {
34+
if (!err) {
35+
console.log(data);
36+
37+
ws.getCredit((err, data) => {
38+
if (!err) {
39+
console.log(data);
40+
}
41+
});
42+
}
43+
});
44+

0 commit comments

Comments
 (0)