validate-domain-alive.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { SOURCE_DIR } from './constants/dir';
  2. import path from 'node:path';
  3. import { isDomainAlive, isRegisterableDomainAlive } 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(async () => {
  40. let registerableDomainAlive, registerableDomain, alive: boolean | undefined;
  41. if (includeAllSubdomain) {
  42. // we only need to check apex domain, because we don't know if there is any stripped subdomain
  43. ({ alive: registerableDomainAlive, registerableDomain } = await isRegisterableDomainAlive(domain));
  44. } else {
  45. ({ alive, registerableDomainAlive, registerableDomain } = await isDomainAlive(domain));
  46. }
  47. bar.increment();
  48. if (!registerableDomainAlive) {
  49. deadDomains.push('.' + registerableDomain);
  50. } else if (!includeAllSubdomain && alive != null && !alive) {
  51. deadDomains.push(domain);
  52. }
  53. });
  54. }
  55. ).then(() => console.log('[crawl]', filepath))
  56. ));
  57. await queue.done();
  58. bar.stop();
  59. console.log();
  60. console.log();
  61. console.log(JSON.stringify(deadDomains));
  62. })();