Lambda function to find IP of a domain

This commit is contained in:
Alicia Sykes
2022-07-09 20:29:36 +01:00
parent 32cc42091d
commit a1496579c4
2 changed files with 90 additions and 19 deletions

View File

@ -0,0 +1,23 @@
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) => {
console.log(err);
if (err) {
callback(null, {
statusCode: 405,
body: JSON.stringify(err),
})
} else {
callback(err, {
statusCode: 200,
body: JSON.stringify({ip, family}),
});
}
});
};