2023-07-07 21:56:58 +02:00
|
|
|
const https = require('https');
|
|
|
|
|
|
|
|
exports.handler = async function(event, context) {
|
2023-07-28 22:46:20 +02:00
|
|
|
const url = (event.queryStringParameters || event.query).url;
|
2023-07-07 21:56:58 +02:00
|
|
|
|
|
|
|
if (!url) {
|
2023-07-10 00:23:50 +02:00
|
|
|
return errorResponse('URL query parameter is required.');
|
2023-07-07 21:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extract hostname from URL
|
|
|
|
const parsedUrl = new URL(url);
|
|
|
|
const domain = parsedUrl.hostname;
|
|
|
|
|
|
|
|
const dnsTypes = ['DNSKEY', 'DS', 'RRSIG'];
|
|
|
|
const records = {};
|
|
|
|
|
|
|
|
for (const type of dnsTypes) {
|
|
|
|
const options = {
|
|
|
|
hostname: 'dns.google',
|
|
|
|
path: `/resolve?name=${encodeURIComponent(domain)}&type=${type}`,
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/dns-json'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
const dnsResponse = await new Promise((resolve, reject) => {
|
|
|
|
const req = https.request(options, res => {
|
|
|
|
let data = '';
|
|
|
|
|
|
|
|
res.on('data', chunk => {
|
|
|
|
data += chunk;
|
|
|
|
});
|
|
|
|
|
|
|
|
res.on('end', () => {
|
|
|
|
resolve(JSON.parse(data));
|
|
|
|
});
|
|
|
|
|
2023-07-10 00:23:50 +02:00
|
|
|
res.on('error', error => {
|
|
|
|
reject(error);
|
|
|
|
});
|
2023-07-07 21:56:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
req.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (dnsResponse.Answer) {
|
|
|
|
records[type] = { isFound: true, answer: dnsResponse.Answer, response: dnsResponse.Answer };
|
|
|
|
} else {
|
|
|
|
records[type] = { isFound: false, answer: null, response: dnsResponse};
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2023-07-10 00:23:50 +02:00
|
|
|
return errorResponse(`Error fetching ${type} record: ${error.message}`);
|
2023-07-07 21:56:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
|
|
|
body: JSON.stringify(records),
|
|
|
|
};
|
|
|
|
};
|
2023-07-10 00:23:50 +02:00
|
|
|
|
|
|
|
const errorResponse = (message, statusCode = 444) => {
|
|
|
|
return {
|
|
|
|
statusCode: statusCode,
|
|
|
|
body: JSON.stringify({ error: message }),
|
|
|
|
};
|
|
|
|
};
|