mirror of
https://github.com/Lissy93/web-check.git
synced 2025-01-10 16:28:18 +01:00
23 lines
598 B
JavaScript
23 lines
598 B
JavaScript
const dns = require('dns');
|
|
|
|
/* Lambda function to fetch the IP address of a given URL */
|
|
exports.handler = function (event, context, callback) {
|
|
const addressParam = event.queryStringParameters.address;
|
|
const address = decodeURIComponent(addressParam)
|
|
.replaceAll('https://', '')
|
|
.replaceAll('http://', '');
|
|
dns.lookup(address, (err, ip, family) => {
|
|
if (err) {
|
|
callback(null, {
|
|
statusCode: 405,
|
|
body: JSON.stringify(err),
|
|
})
|
|
} else {
|
|
callback(err, {
|
|
statusCode: 200,
|
|
body: JSON.stringify({ip, family}),
|
|
});
|
|
}
|
|
});
|
|
};
|