Removes logs, updates traceroute return types

This commit is contained in:
Alicia Sykes 2023-07-05 01:48:12 +01:00
parent 733f86c5e8
commit b8705ee48e
2 changed files with 3 additions and 7 deletions

View File

@ -6,27 +6,21 @@ const PORTS = [21, 22, 25, 80, 110, 143, 443, 587, 993, 995, 3306, 3389, 5900, 8
async function checkPort(port, domain) {
return new Promise(resolve => {
const socket = new net.Socket();
console.log(port, 'Init');
socket.setTimeout(1500); // you may want to adjust the timeout
socket.once('connect', () => {
console.log(port, 'Connected!');
socket.destroy();
resolve(port);
});
socket.once('timeout', () => {
console.log(port, 'Timedout');
socket.destroy();
});
socket.once('error', (e) => {
console.log(port, 'Errored', e);
socket.destroy();
});
console.log(port, 'End');
socket.connect(port, domain);
});
}

View File

@ -7,6 +7,7 @@ const traceroutePromise = util.promisify(traceroute.trace);
exports.handler = async function(event, context) {
const urlString = event.queryStringParameters.url;
const startTime = Date.now();
try {
if (!urlString) {
@ -22,9 +23,10 @@ exports.handler = async function(event, context) {
}
const result = await traceroutePromise(host);
const timeTaken = Date.now() - startTime;
return {
statusCode: 200,
body: JSON.stringify({ message: "Traceroute completed!", result }),
body: JSON.stringify({ message: "Traceroute completed!", result, timeTaken }),
};
} catch (err) {
return {