Skip to content

Instantly share code, notes, and snippets.

@bslavin
Created July 31, 2019 20:54
Show Gist options
  • Save bslavin/063956fbe53b1e364d859e3d85d50a65 to your computer and use it in GitHub Desktop.
Save bslavin/063956fbe53b1e364d859e3d85d50a65 to your computer and use it in GitHub Desktop.
Find sites with unhealthy SPF record
const parse = require('csv-parse');
const { Axios: axios } = require('axios-observable');
const { from, empty } = require('rxjs');
const { concatMap, catchError, map } = require('rxjs/operators');
const { appendFileSync, writeFileSync } = require('fs');
const path = 'unhealthy.csv';
const main = async () => {
const { data } = await axios
.get(
'https://gist.githubusercontent.com/mbejda/45db05ea50e79bc42016/raw/52d5ca99398b495e096f6eace20f5872129633e3/Fortune-1000-Company-Twitter-Accounts.csv',
)
.toPromise();
parse(data, (err, records) => {
if (!err) {
const domains = records.slice(1).map(([record]) => record);
writeFileSync(path, 'Domain, DNS query count\n');
from(domains.slice(1))
.pipe(
concatMap(domain =>
axios
.post('http://localhost/analyse', { domain })
.pipe(catchError(err => empty()))
.pipe(map(({ data }) => data)),
),
)
.pipe(catchError(err => console.log('ERR', err)))
.subscribe(resp => {
if (resp.healthy) {
console.log(`${resp.url} is healthy.`);
} else {
const {
curr_spf_repr,
flattened_includes,
saved_query_count,
...rest
} = resp;
console.log(`${resp.url} has problems: `, rest);
appendFileSync(path, `${rest.url},${rest.query_count}\n`);
}
});
}
});
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment