validate-domain-alive.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { SOURCE_DIR } from './constants/dir';
  2. import path from 'node:path';
  3. import { isDomainAlive } from './lib/is-domain-alive';
  4. import { fdir as Fdir } from 'fdir';
  5. import runAgainstSourceFile from './lib/run-against-source-file';
  6. import cliProgress from 'cli-progress';
  7. import { newQueue } from '@henrygd/queue';
  8. const queue = newQueue(32);
  9. const deadDomains: string[] = [];
  10. (async () => {
  11. const domainSets = await new Fdir()
  12. .withFullPaths()
  13. .filter((filePath, isDirectory) => {
  14. if (isDirectory) return false;
  15. const extname = path.extname(filePath);
  16. return extname === '.txt' || extname === '.conf';
  17. })
  18. .crawl(SOURCE_DIR + path.sep + 'domainset')
  19. .withPromise();
  20. const domainRules = await new Fdir()
  21. .withFullPaths()
  22. .filter((filePath, isDirectory) => {
  23. if (isDirectory) return false;
  24. const extname = path.extname(filePath);
  25. return extname === '.txt' || extname === '.conf';
  26. })
  27. .crawl(SOURCE_DIR + path.sep + 'non_ip')
  28. .withPromise();
  29. const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
  30. bar.start(0, 0);
  31. await Promise.all([
  32. ...domainRules,
  33. ...domainSets
  34. ].map(
  35. filepath => runAgainstSourceFile(
  36. filepath,
  37. (domain: string, includeAllSubdomain: boolean) => {
  38. bar.setTotal(bar.getTotal() + 1);
  39. return queue.add(
  40. () => isDomainAlive(domain, includeAllSubdomain).then((alive) => {
  41. bar.increment();
  42. if (alive) {
  43. return;
  44. }
  45. deadDomains.push(includeAllSubdomain ? '.' + domain : domain);
  46. })
  47. );
  48. }
  49. ).then(() => console.log('[crawl]', filepath))
  50. ));
  51. await queue.done();
  52. bar.stop();
  53. console.log();
  54. console.log();
  55. console.log(JSON.stringify(deadDomains));
  56. })();