Skip to content

Commit

Permalink
Fixed an issue when some ip v6 weren't found
Browse files Browse the repository at this point in the history
  • Loading branch information
Umkus committed Oct 9, 2024
1 parent 81fcede commit 09a7098
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "ip-index",
"version": "2.0.17",
"version": "2.1.0",
"repository": "https://github.com/Umkus/ip-index.git",
"license": "UNLICENCED",
"description": "Block-list containing IPs belonging to hosting data centers",
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ function getPosition(subnet, start) {
const part = subnet.split(/[:\.]/)[start]
const isIpV6 = subnet.includes(':')

if (!part) {
return null
}

return parseInt(part, isIpV6 ? 16 : 10)
}

// Check if ip 4 vs 6

function indexRow(item, index, indexes) {
if (!index || !item) {
if (!item) {
return null
}

Expand Down Expand Up @@ -127,7 +131,7 @@ export function getIpInfo(ip) {
ipPosition2 = availableKeys.reverse().find((key) => key <= ipPosition2)

if (!indexes[ipPosition1][ipPosition2]) {
return []
return indexes[ipPosition1][null] || []
}
}

Expand Down

0 comments on commit 09a7098

Please sign in to comment.