mirror of
https://github.com/Lissy93/web-check.git
synced 2025-08-09 05:04:31 +02:00
✨ Lambda function to find IP of a domain
This commit is contained in:
23
server/lambda/find-url-ip.js
Normal file
23
server/lambda/find-url-ip.js
Normal 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}),
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user