Last active
July 25, 2020 19:16
-
-
Save amcolash/4159c0e6e609f50668484fde5d4cb5e1 to your computer and use it in GitHub Desktop.
Merge IP blocklists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Simple node script to merge 2 IP blocklists into a single one for use with Synology */ | |
const fs = require('fs'); | |
const path = require('path'); | |
function makeSet(file) { | |
const split = file.split(/\r?\n/); | |
const set = new Set(); | |
split.forEach(ip => set.add(ip)); | |
return set; | |
} | |
const myFile = fs.readFileSync(path.join(__dirname, 'mylist.txt'), 'UTF-8'); | |
const theirFile = fs.readFileSync(path.join(__dirname, 'deny-ip-list.txt'), 'UTF-8'); | |
const mySet = makeSet(myFile); | |
const theirSet = makeSet(theirFile); | |
console.log(`My list size: ${mySet.size}`); | |
console.log(`Their list size: ${theirSet.size}`); | |
const merged = new Set(); | |
mySet.forEach(ip => merged.add(ip)); | |
theirSet.forEach(ip => merged.add(ip)); | |
console.log(`Merged size: ${merged.size}`); | |
let combined = ""; | |
merged.forEach((ip) => { | |
combined = combined.concat(`${ip}\n`); | |
}); | |
fs.writeFileSync(path.join(__dirname, 'combined.txt'), combined); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment