Skip to content

Instantly share code, notes, and snippets.

@nkcmr

nkcmr/ad-tracker-block.js

Last active Aug 10, 2016
Embed
What would you like to do?
ad/tracker blocker that works at a system level
'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