I found a Node module that does exactly what you need.
Multicast-DNS is capable of querying mDNS IPs to the standard IP format. The snippet on their README does what you need:
var mdns = require('multicast-dns')()
mdns.on('response', function(response) {
console.log('got a response packet:', response)
})
mdns.on('query', function(query) {
console.log('got a query packet:', query)
})
// lets query for an A record for 'brunhilde.local'
mdns.query({
questions:[{
name: 'brunhilde.local',
type: 'A'
}]
})
Obviously you need to replace brunhilde.local
with a valid mDNS ip. I simplified the code into this:
function query(mdns_ip){
return new Promise((resolve, reject)=>{
mdns.on('response', function(response) {
if(response.rcode === 'NOERROR'){
resolve(response.answers[0].data)
mdns.destroy()
} else {
reject(response.rcode)
mdns.destroy()
}
})
mdns.query({
questions:[{
name: mdns_ip,
type: 'A'
}]
})
})
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…