Log time and targeted host

This commit is contained in:
2024-07-24 19:15:07 +02:00
parent c864d2e625
commit 94ef11a0c8
2 changed files with 21 additions and 4 deletions

View File

@@ -2,13 +2,20 @@ import { createServer } from 'node:http';
import { clearInterval, setInterval } from 'node:timers';
const server = createServer((req, res) => {
const connOpenDate = new Date();
const attacker = req.headers['x-forwarded-for'];
const host = req.headers['x-targeted-host'];
console.log(
`Caught ${req.headers['x-forwarded-for']} on ${req.method} ${req.url}`
`[${connOpenDate.toLocaleString()}] ${attacker} targeted ${host} on ${
req.method
} ${req.url}`
);
let msg = ':) you are an idiot hahahahaha :)';
const msg = ':) you are an idiot hahahahaha :)';
let charIdx = 0;
let intervalId = setInterval(() => {
const intervalId = setInterval(() => {
if (charIdx === msg.length) {
charIdx = 0;
res.write('\n');
@@ -17,7 +24,16 @@ const server = createServer((req, res) => {
}
}, 3000);
res.once('close', () => clearInterval(intervalId));
res.once('close', () => {
const connCloseDate = new Date();
const timeDiff = connCloseDate.getTime() - connOpenDate.getTime();
const diffText = new Date(timeDiff).toISOString().substring(11, 19);
clearInterval(intervalId);
console.log(
`[${connCloseDate.toLocaleString()}] ${attacker} aborted connection after ${diffText}`
);
});
});
server.listen(3000);