validate-domain-alive.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. const deadDomains: string[] = [];
  7. (async () => {
  8. const domainSets = await new Fdir()
  9. .withFullPaths()
  10. .filter((filePath, isDirectory) => {
  11. if (isDirectory) return false;
  12. const extname = path.extname(filePath);
  13. return extname === '.txt' || extname === '.conf';
  14. })
  15. .crawl(SOURCE_DIR + path.sep + 'domainset')
  16. .withPromise();
  17. const domainRules = await new Fdir()
  18. .withFullPaths()
  19. .filter((filePath, isDirectory) => {
  20. if (isDirectory) return false;
  21. const extname = path.extname(filePath);
  22. return extname === '.txt' || extname === '.conf';
  23. })
  24. .crawl(SOURCE_DIR + path.sep + 'non_ip')
  25. .withPromise();
  26. const promises: Array<Promise<void>> = [];
  27. await Promise.all([
  28. ...domainRules,
  29. ...domainSets
  30. ].map(
  31. filepath => runAgainstSourceFile(
  32. filepath,
  33. (domain: string, includeAllSubdomain: boolean) => promises.push(
  34. isDomainAlive(domain, includeAllSubdomain).then((alive) => {
  35. if (alive) {
  36. return;
  37. }
  38. deadDomains.push(includeAllSubdomain ? '.' + domain : domain);
  39. })
  40. )
  41. ).then(() => console.log('[crawl]', filepath))
  42. ));
  43. await Promise.all(promises);
  44. console.log();
  45. console.log();
  46. console.log(JSON.stringify(deadDomains));
  47. })();