移除dns:ipaddress
							parent
							
								
									f9f7d2643f
								
							
						
					
					
						commit
						4097a34c78
					
				| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
const matchUtil = require('../../utils/util.match')
 | 
			
		||||
const DNSOverPreSetIpList = require('./preset.js')
 | 
			
		||||
const DNSOverIpAddress = require('./ipaddress.js')
 | 
			
		||||
const DNSOverHTTPS = require('./https.js')
 | 
			
		||||
const DNSOverTLS = require('./tls.js')
 | 
			
		||||
const DNSOverTCP = require('./tcp.js')
 | 
			
		||||
| 
						 | 
				
			
			@ -39,9 +38,7 @@ module.exports = {
 | 
			
		|||
        conf.type = conf.type.toLowerCase()
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (conf.type === 'ipaddress') {
 | 
			
		||||
        dnsMap[provider] = new DNSOverIpAddress(provider, conf.cacheSize, preSetIpList)
 | 
			
		||||
      } else if (conf.type === 'https') {
 | 
			
		||||
      if (conf.type === 'https') {
 | 
			
		||||
        dnsMap[provider] = new DNSOverHTTPS(provider, conf.cacheSize, preSetIpList, server)
 | 
			
		||||
      } else if (conf.type === 'tls') {
 | 
			
		||||
        if (server.startsWith('tls://')) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,29 +0,0 @@
 | 
			
		|||
const axios = require('axios')
 | 
			
		||||
const log = require('../../utils/util.log.server')
 | 
			
		||||
const BaseDNS = require('./base')
 | 
			
		||||
 | 
			
		||||
module.exports = class DNSOverIpAddress extends BaseDNS {
 | 
			
		||||
  async _lookup (hostname) {
 | 
			
		||||
    const url = `https://${hostname}.ipaddress.com`
 | 
			
		||||
 | 
			
		||||
    // const res = fs.readFileSync(path.resolve(__dirname, './data.txt')).toString()
 | 
			
		||||
    const res = await axios.get(url)
 | 
			
		||||
    if (res.status !== 200 && res.status !== 201) {
 | 
			
		||||
      log.error(`[dns] get ${hostname} ipaddress: error: ${res}`)
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
    const ret = res.data
 | 
			
		||||
 | 
			
		||||
    const regexp = /<tr><th>IP Address<\/th><td><ul class="comma-separated"><li>([^<]*)<\/li><\/ul><\/td><\/tr>/g
 | 
			
		||||
    const matched = regexp.exec(ret)
 | 
			
		||||
    let ip = null
 | 
			
		||||
 | 
			
		||||
    if (matched && matched.length >= 1) {
 | 
			
		||||
      ip = matched[1]
 | 
			
		||||
      log.info(`[dns] get ${hostname} ipaddress:${ip}`)
 | 
			
		||||
      return [ip]
 | 
			
		||||
    }
 | 
			
		||||
    log.warn(`[dns] get ${hostname} ipaddress: error`)
 | 
			
		||||
    return null
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -3,11 +3,6 @@ const SpeedTest = require('../src/lib/speed/index.js')
 | 
			
		|||
const SpeedTester = require('../src/lib/speed/SpeedTester.js')
 | 
			
		||||
 | 
			
		||||
const dnsMap = dns.initDNS({
 | 
			
		||||
  // ipaddress: {
 | 
			
		||||
  //   type: 'ipaddress',
 | 
			
		||||
  //   server: 'ipaddress',
 | 
			
		||||
  //   cacheSize: 1000
 | 
			
		||||
  // },
 | 
			
		||||
  cloudflare: {
 | 
			
		||||
    type: 'https',
 | 
			
		||||
    server: 'https://1.1.1.1/dns-query',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,12 +4,6 @@ import dns from '../src/lib/dns/index.js'
 | 
			
		|||
const presetIp = '100.100.100.100'
 | 
			
		||||
 | 
			
		||||
const dnsProviders = dns.initDNS({
 | 
			
		||||
  ipaddress: {
 | 
			
		||||
    type: 'ipaddress',
 | 
			
		||||
    server: 'ipaddress',
 | 
			
		||||
    cacheSize: 1000,
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  // https
 | 
			
		||||
  cloudflare: {
 | 
			
		||||
    type: 'https',
 | 
			
		||||
| 
						 | 
				
			
			@ -93,6 +87,7 @@ const dnsProviders = dns.initDNS({
 | 
			
		|||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const presetHostname = 'xxx.com'
 | 
			
		||||
const hostname1 = 'github.com'
 | 
			
		||||
const hostname2 = 'api.github.com'
 | 
			
		||||
| 
						 | 
				
			
			@ -103,18 +98,6 @@ const hostname6 = 'gh2.docmirror.top'
 | 
			
		|||
 | 
			
		||||
let ip
 | 
			
		||||
 | 
			
		||||
// const test = '111<tr><th>IP Address</th><td><ul class="comma-separated"><li>140.82.113.4</li></ul></td></tr>2222'
 | 
			
		||||
// // <tr><th>IP Address</th><td><ul class="comma-separated"><li>140.82.113.4</li></ul></td></tr>
 | 
			
		||||
// // <tr><th>IP Address</th><td><ul class="comma-separated"><li>(.*)</li></ul></td></tr>
 | 
			
		||||
// const regexp = /<tr><th>IP Address<\/th><td><ul class="comma-separated"><li>(.*)<\/li><\/ul><\/td><\/tr>/
 | 
			
		||||
// const matched = regexp.exec(test)
 | 
			
		||||
// console.log('data:', matched)
 | 
			
		||||
//
 | 
			
		||||
// console.log('\n--------------- test ipaddress ---------------\n')
 | 
			
		||||
// ip = await dnsProviders.ipaddress.lookup(hostname1)
 | 
			
		||||
// console.log('===> test ipaddress:', ip, '\n\n')
 | 
			
		||||
assert.strictEqual(dnsProviders.ipaddress.type, 'ipaddress')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
console.log('\n--------------- test PreSet ---------------\n')
 | 
			
		||||
ip = await dnsProviders.PreSet.lookup(presetHostname)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue