feat: dns: Use node's built in isIP check instead of regex (#410)
Fixes #408
This commit is contained in:
parent
f4150b2324
commit
bdb926d6b2
|
@ -1,4 +1,5 @@
|
|||
import dns from 'node:dns'
|
||||
import { isIP } from 'node:net'
|
||||
import punycode from 'punycode/punycode.js'
|
||||
|
||||
export default class DnsResolver {
|
||||
|
@ -9,12 +10,12 @@ export default class DnsResolver {
|
|||
this.logger = logger
|
||||
}
|
||||
|
||||
isIp (host) {
|
||||
return !!host.match(/\d+\.\d+\.\d+\.\d+/)
|
||||
}
|
||||
|
||||
/**
|
||||
* Response port will only be present if srv record was involved.
|
||||
* Resolve a host name to its IP, if the given host name is already
|
||||
* an IP address no request is made.
|
||||
*
|
||||
* If a srvRecordPrefix is provided a SRV request will be made and the
|
||||
* port returned will be included in the output.
|
||||
* @param {string} host
|
||||
* @param {number} ipFamily
|
||||
* @param {string=} srvRecordPrefix
|
||||
|
@ -23,7 +24,8 @@ export default class DnsResolver {
|
|||
async resolve (host, ipFamily, srvRecordPrefix) {
|
||||
this.logger.debug('DNS Lookup: ' + host)
|
||||
|
||||
if (this.isIp(host)) {
|
||||
// Check if host is IPv4 or IPv6
|
||||
if (isIP(host) === 4 || isIP(host) === 6) {
|
||||
this.logger.debug('Raw IP Address: ' + host)
|
||||
return { address: host }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue