Last active
August 10, 2016 20:27
-
-
Save nkcmr/1b37947e352aa3ce2a3c606525b1d9be to your computer and use it in GitHub Desktop.
ad/tracker blocker that works at a system level
This file contains hidden or 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
'use strict' | |
const blacklist = [ | |
/analytics/, | |
/fullstory/, | |
/amplitude/, | |
/crashlytics\.com/, | |
/doubleclick\.net/, | |
/chartbeat\.(net|com)/, | |
/deepintent\.com/, | |
/amazon-adsystem\.com/, | |
/b\.scorecardresearch\.com/, | |
/px\.dynamicyield\.com/, | |
/js-agent\.newrelic\.com/, | |
/mobile-collector\.newrelic\.com/, | |
/urbanairship\.com/, | |
/moatads\.com/, | |
/engine\.mobileapptracking\.com/, | |
/m\.quantcount\.com/, | |
/ingest\.crittercism\.com/, | |
/demdex\.(net|com)/, | |
/flurry\.com/, | |
/tubemogel\.com/, | |
/localytics\.com/, | |
/adroll\.com/, | |
/ensighten\.com/, | |
/appsflyer\.com/, | |
/outbrain\.com/, | |
/gigya\.com/, | |
/krxd\.net/, | |
/advertising\.com/, | |
/(metrics)\.cnn\.com/, | |
/postrelease\.com/, | |
/nativo\.net/, | |
/liverail\.com/, | |
/btrll\.com/, | |
/clicktale\.net/, | |
/adsrvr\.org/, | |
/adjust\.com/, | |
/mixpanel\.com/, | |
/quantserve\.com/, | |
/skimresources\.com/, | |
/exelator\.com/, | |
/rubiconproject\.com/ | |
] | |
var passive = false | |
process.stdin.on('data', data => { | |
var s = data.toString('utf8').trim() | |
if (s === 'passive') { | |
console.log(chalk.blue('passive mode: on')) | |
passive = true | |
} else if (s === 'block') { | |
console.log(chalk.yellow('passive mode: off')) | |
passive = false | |
} | |
}) | |
const socks = require('socksv5') | |
const chalk = require('chalk') | |
const srv = socks.createServer((info, accept, deny) => { | |
for (let r of blacklist) { | |
if (r.test(info.dstAddr)) { | |
if (!passive) { | |
console.log(chalk.red(`TRACKER: ${info.dstAddr}`)) | |
deny() | |
return | |
} else { | |
console.log(chalk.yellow(`TRACKER: ${info.dstAddr}`)) | |
break | |
} | |
} | |
} | |
console.log(chalk.green(`${info.cmd}: ${info.dstAddr}:${info.dstPort}`)) | |
accept() | |
}) | |
srv.listen(8089, '0.0.0.0', () => { | |
console.log(chalk.blue('SOCKS server listening on port 8089')) | |
}) | |
srv.useAuth(socks.auth.None()) | |
// to configure an iOS device | |
const pac = `function FindProxyForURL(url, host) | |
{ | |
return "SOCKS ${require('os').hostname()}:8089"; | |
} | |
` | |
require('http').createServer((req, res) => { | |
res.end(pac) | |
}).listen(8090) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment