parse-dnsmasq.js 791 B

123456789101112131415161718192021222324252627
  1. const { fetchRemoteTextAndCreateReadlineInterface } = require('./fetch-remote-text-by-line');
  2. const tldts = require('tldts');
  3. const isDomainLoose = (domain) => {
  4. const { isIcann, isPrivate, isIp } = tldts.parse(domain);
  5. return !!(!isIp && (isIcann || isPrivate));
  6. };
  7. /**
  8. * @param {string | URL} url
  9. */
  10. const parseFelixDnsmasq = async (url) => {
  11. /** @type {string[]} */
  12. const res = [];
  13. for await (const line of await fetchRemoteTextAndCreateReadlineInterface(url)) {
  14. if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
  15. const domain = line.replace('server=/', '').replace('/114.114.114.114', '');
  16. if (isDomainLoose(domain)) {
  17. res.push(domain);
  18. }
  19. }
  20. }
  21. return res;
  22. };
  23. module.exports.parseFelixDnsmasq = parseFelixDnsmasq;