ip2proxy-nodejs
Advanced tools
+1
-1
| { | ||
| "name": "ip2proxy-nodejs", | ||
| "version": "4.1.0", | ||
| "version": "4.2.0", | ||
| "description": "IP2Proxy proxy detection component", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,4 +5,7 @@ export class IP2Proxy { | ||
| read8(position: any): any; | ||
| read8Row(position: any, buffer: any): any; | ||
| read32(position: any, isBigInt: any): any; | ||
| read32Row(position: any, buffer: any): any; | ||
| read128Row(position: any, buffer: any): any; | ||
| read32Or128Row(position: any, buffer: any, len: any): any; | ||
| read32Or128(position: any, ipType: any): any; | ||
@@ -76,2 +79,2 @@ read128(position: any): any; | ||
| #private; | ||
| } | ||
| } |
+108
-51
@@ -7,3 +7,3 @@ var net = require("net"); | ||
| // For BIN queries | ||
| const VERSION = "4.1.0"; | ||
| const VERSION = "4.2.0"; | ||
| const MAX_INDEX = 65536; | ||
@@ -109,2 +109,4 @@ const COUNTRY_POSITION = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]; | ||
| baseAddressIPV6: 0, | ||
| indexed: 0, | ||
| indexedIPV6: 0, | ||
| indexBaseAddress: 0, | ||
@@ -173,2 +175,7 @@ indexBaseAddressIPV6: 0, | ||
| // Read 8 bits integer in the buffer | ||
| read8Row(position, buffer) { | ||
| return buffer.readUInt8(position); | ||
| } | ||
| // Read 32 bits integer in the database | ||
@@ -185,2 +192,25 @@ read32(position, isBigInt) { | ||
| // Read 128 bits integer in the buffer | ||
| read128Row(position, buffer) { | ||
| let myBig = bigInt(); // zero | ||
| let bitShift = 8; | ||
| for (let x = 0; x < 16; x++) { | ||
| let pos = position + x; | ||
| myBig = myBig.add( | ||
| bigInt(this.read8Row(pos, buffer)).shiftLeft(bitShift * x) | ||
| ); | ||
| } | ||
| return myBig; | ||
| } | ||
| read32Or128Row(position, buffer, len) { | ||
| if (len == 4) { | ||
| return this.read32Row(position, buffer); | ||
| } else if (len == 16) { | ||
| return this.read128Row(position, buffer); | ||
| } else { | ||
| return 0; | ||
| } | ||
| } | ||
| read32Or128(position, ipType) { | ||
@@ -204,8 +234,6 @@ if (ipType == 4) { | ||
| readStr(position) { | ||
| let readBytes = 1; | ||
| return this.readBin( | ||
| this.readBin(readBytes, position, "int8"), | ||
| position + 1, | ||
| "str" | ||
| ); | ||
| let readBytes = 256; // max size of string field + 1 byte for the length | ||
| let row = this.readRow(readBytes, position + 1); | ||
| let len = this.read8Row(0, row); | ||
| return row.toString("utf8", 1, len + 1); | ||
| } | ||
@@ -221,17 +249,20 @@ | ||
| this.#myDB.dbType = this.read8(1); | ||
| this.#myDB.dbColumn = this.read8(2); | ||
| this.#myDB.dbYear = this.read8(3); | ||
| this.#myDB.dbMonth = this.read8(4); | ||
| this.#myDB.dbDay = this.read8(5); | ||
| this.#myDB.dbCount = this.read32(6); | ||
| this.#myDB.baseAddress = this.read32(10); | ||
| this.#myDB.dbCountIPV6 = this.read32(14); | ||
| this.#myDB.baseAddressIPV6 = this.read32(18); | ||
| this.#myDB.indexBaseAddress = this.read32(22); | ||
| this.#myDB.indexBaseAddressIPV6 = this.read32(26); | ||
| this.#myDB.productCode = this.read8(30); | ||
| let len = 64; // 64-byte header | ||
| let row = this.readRow(len, 1); | ||
| this.#myDB.dbType = this.read8Row(0, row); | ||
| this.#myDB.dbColumn = this.read8Row(1, row); | ||
| this.#myDB.dbYear = this.read8Row(2, row); | ||
| this.#myDB.dbMonth = this.read8Row(3, row); | ||
| this.#myDB.dbDay = this.read8Row(4, row); | ||
| this.#myDB.dbCount = this.read32Row(5, row); | ||
| this.#myDB.baseAddress = this.read32Row(9, row); | ||
| this.#myDB.dbCountIPV6 = this.read32Row(13, row); | ||
| this.#myDB.baseAddressIPV6 = this.read32Row(17, row); | ||
| this.#myDB.indexBaseAddress = this.read32Row(21, row); | ||
| this.#myDB.indexBaseAddressIPV6 = this.read32Row(25, row); | ||
| this.#myDB.productCode = this.read8Row(29, row); | ||
| // below 2 fields just read for now, not being used yet | ||
| this.#myDB.productType = this.read8(31); | ||
| this.#myDB.fileSize = this.read32(32); | ||
| this.#myDB.productType = this.read8Row(30, row); | ||
| this.#myDB.fileSize = this.read32Row(31, row); | ||
@@ -247,2 +278,10 @@ // check if is correct BIN (should be 2 for IP2Proxy BIN file), also checking for zipped file (PK being the first 2 chars) | ||
| if (this.#myDB.indexBaseAddress > 0) { | ||
| this.#myDB.indexed = 1; | ||
| } | ||
| if (this.#myDB.dbCountIPV6 > 0 && this.#myDB.indexBaseAddressIPV6 > 0) { | ||
| this.#myDB.indexedIPV6 = 1; | ||
| } | ||
| this.#ipV4ColumnSize = this.#myDB.dbColumn << 2; // 4 bytes each column | ||
@@ -295,18 +334,28 @@ this.#ipV6ColumnSize = 16 + ((this.#myDB.dbColumn - 1) << 2); // 4 bytes each column, except IPFrom column which is 16 bytes | ||
| let pointer = this.#myDB.indexBaseAddress; | ||
| if (this.#myDB.indexed == 1) { | ||
| len = MAX_INDEX; | ||
| if (this.#myDB.indexedIPV6 == 1) { | ||
| len += MAX_INDEX; | ||
| } | ||
| len *= 8; // 4 bytes for both From/To | ||
| for (let x = 0; x < MAX_INDEX; x++) { | ||
| this.#indexArrayIPV4[x] = Array(2); | ||
| this.#indexArrayIPV4[x][0] = this.read32(pointer); | ||
| this.#indexArrayIPV4[x][1] = this.read32(pointer + 4); | ||
| pointer += 8; | ||
| } | ||
| row = this.readRow(len, this.#myDB.indexBaseAddress); | ||
| if (this.#myDB.indexBaseAddressIPV6 > 0) { | ||
| let pointer = 0; | ||
| for (let x = 0; x < MAX_INDEX; x++) { | ||
| this.#indexArrayIPV6[x] = Array(2); | ||
| this.#indexArrayIPV6[x][0] = this.read32(pointer); | ||
| this.#indexArrayIPV6[x][1] = this.read32(pointer + 4); | ||
| this.#indexArrayIPV4[x] = Array(2); | ||
| this.#indexArrayIPV4[x][0] = this.read32Row(pointer, row); | ||
| this.#indexArrayIPV4[x][1] = this.read32Row(pointer + 4, row); | ||
| pointer += 8; | ||
| } | ||
| if (this.#myDB.indexedIPV6 == 1) { | ||
| for (let x = 0; x < MAX_INDEX; x++) { | ||
| this.#indexArrayIPV6[x] = Array(2); | ||
| this.#indexArrayIPV6[x][0] = this.read32Row(pointer, row); | ||
| this.#indexArrayIPV6[x][1] = this.read32Row(pointer + 4, row); | ||
| pointer += 8; | ||
| } | ||
| } | ||
| } | ||
@@ -349,2 +398,4 @@ loadOK = true; | ||
| this.#myDB.dbCountIPV6 = 0; | ||
| this.#myDB.indexed = 0; | ||
| this.#myDB.indexedIPV6 = 0; | ||
| this.#myDB.indexBaseAddress = 0; | ||
@@ -377,4 +428,5 @@ this.#myDB.indexBaseAddressIPV6 = 0; | ||
| let ipTo; | ||
| let firstCol; | ||
| let firstCol = 4; // IP From is 4 bytes | ||
| let row; | ||
| let fullRow; | ||
@@ -388,5 +440,7 @@ if (ipType == 4) { | ||
| indexAddress = ipNumber >>> 16; | ||
| low = this.#indexArrayIPV4[indexAddress][0]; | ||
| high = this.#indexArrayIPV4[indexAddress][1]; | ||
| if (this.#myDB.indexed == 1) { | ||
| indexAddress = ipNumber >>> 16; | ||
| low = this.#indexArrayIPV4[indexAddress][0]; | ||
| high = this.#indexArrayIPV4[indexAddress][1]; | ||
| } | ||
| } else if (ipType == 6) { | ||
@@ -414,9 +468,14 @@ MAX_IP_RANGE = MAX_IPV6_RANGE; | ||
| } | ||
| indexAddress = ipNumber >>> 16; | ||
| low = this.#indexArrayIPV4[indexAddress][0]; | ||
| high = this.#indexArrayIPV4[indexAddress][1]; | ||
| if (this.#myDB.indexed == 1) { | ||
| indexAddress = ipNumber >>> 16; | ||
| low = this.#indexArrayIPV4[indexAddress][0]; | ||
| high = this.#indexArrayIPV4[indexAddress][1]; | ||
| } | ||
| } else { | ||
| indexAddress = ipNumber.shiftRight(112).toJSNumber(); | ||
| low = this.#indexArrayIPV6[indexAddress][0]; | ||
| high = this.#indexArrayIPV6[indexAddress][1]; | ||
| firstCol = 16; // IPv6 is 16 bytes | ||
| if (this.#myDB.indexedIPV6 == 1) { | ||
| indexAddress = ipNumber.shiftRight(112).toJSNumber(); | ||
| low = this.#indexArrayIPV6[indexAddress][0]; | ||
| high = this.#indexArrayIPV6[indexAddress][1]; | ||
| } | ||
| } | ||
@@ -435,8 +494,10 @@ } | ||
| while (low <= high) { | ||
| mid = parseInt((low + high) / 2); | ||
| mid = Math.trunc((low + high) / 2); | ||
| rowOffset = baseAddress + mid * columnSize; | ||
| rowOffset2 = rowOffset + columnSize; | ||
| ipFrom = this.read32Or128(rowOffset, ipType); | ||
| ipTo = this.read32Or128(rowOffset2, ipType); | ||
| // reading IP From + whole row + next IP From | ||
| fullRow = this.readRow(columnSize + firstCol, rowOffset); | ||
| ipFrom = this.read32Or128Row(0, fullRow, firstCol); | ||
| ipTo = this.read32Or128Row(columnSize, fullRow, firstCol); | ||
@@ -449,9 +510,5 @@ ipFrom = bigInt(ipFrom); | ||
| firstCol = 4; | ||
| if (ipType == 6) { | ||
| firstCol = 16; | ||
| } | ||
| let rowLen = columnSize - firstCol; | ||
| row = fullRow.subarray(firstCol, firstCol + rowLen); // extract the actual row data | ||
| row = this.readRow(columnSize - firstCol, rowOffset + firstCol); | ||
| if (this.#proxyTypeEnabled) { | ||
@@ -458,0 +515,0 @@ if ( |
+20
-20
@@ -1,7 +0,7 @@ | ||
| const {IP2Proxy, IP2ProxyWebService} = require("ip2proxy-nodejs"); | ||
| // const {IP2Proxy, IP2ProxyWebService} = require("./ip2proxy.js"); | ||
| // const {IP2Proxy, IP2ProxyWebService} = require("ip2proxy-nodejs"); | ||
| const {IP2Proxy, IP2ProxyWebService} = require("./ip2proxy.js"); | ||
| let ip2proxy = new IP2Proxy(); | ||
| ip2proxy.open('PX11.BIN'); | ||
| ip2proxy.open("C:\\Users\\Kervin\\Desktop\\IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN"); | ||
@@ -12,3 +12,3 @@ console.log("Module version " + ip2proxy.getModuleVersion()); | ||
| testip = ['8.8.8.8', '199.83.103.79', '199.83.103.279']; | ||
| testip = ['8.8.8.8', '199.83.103.79', '199.83.103.279', '2001:0:4136:e378:8000:63bf:f7f7:f7f7', '2002:0803:2200::0803:2200', '2600:1f18:45b0:5b00:f5d8:4183:7710:ceec', '2a02:2498:e003:10:216:3eff:fe97:a277', '2600:387:2:813::5a', '2601:281:8281:2f60:f420:4977:b2cc:3162']; | ||
@@ -25,22 +25,22 @@ for (let x = 0; x < testip.length; x++) { | ||
| let ws = new IP2ProxyWebService(); | ||
| // let ws = new IP2ProxyWebService(); | ||
| let ip = "8.8.8.8"; | ||
| let apiKey = "YOUR_API_KEY"; | ||
| let apiPackage = "PX11"; | ||
| let useSSL = true; | ||
| // let ip = "8.8.8.8"; | ||
| // let apiKey = "YOUR_API_KEY"; | ||
| // let apiPackage = "PX11"; | ||
| // let useSSL = true; | ||
| ws.open(apiKey, apiPackage, useSSL); | ||
| // ws.open(apiKey, apiPackage, useSSL); | ||
| ws.lookup(ip, (err, data) => { | ||
| if (!err) { | ||
| console.log(data); | ||
| // ws.lookup(ip, (err, data) => { | ||
| // if (!err) { | ||
| // console.log(data); | ||
| ws.getCredit((err, data) => { | ||
| if (!err) { | ||
| console.log(data); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| // ws.getCredit((err, data) => { | ||
| // if (!err) { | ||
| // console.log(data); | ||
| // } | ||
| // }); | ||
| // } | ||
| // }); | ||
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
38739
6.82%950
5.91%