forked from saumyayadav25/cpp-dsa-sheet-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-ip.js
More file actions
47 lines (39 loc) · 1.46 KB
/
get-ip.js
File metadata and controls
47 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Run this script to get your current IP address for MongoDB Atlas whitelisting
// Usage: node get-ip.js
const https = require('https');
console.log('🔍 Getting your current IP address for MongoDB Atlas whitelisting...\n');
// Get IP from multiple services for reliability
const ipServices = [
'https://api.ipify.org',
'https://ipinfo.io/ip',
'https://icanhazip.com'
];
async function getIP(url) {
return new Promise((resolve, reject) => {
https.get(url, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => resolve(data.trim()));
}).on('error', reject);
});
}
async function getAllIPs() {
console.log('📡 Checking IP addresses from multiple services:\n');
for (const service of ipServices) {
try {
const ip = await getIP(service);
console.log(`✅ ${service}: ${ip}`);
} catch (error) {
console.log(`❌ ${service}: Failed to get IP`);
}
}
console.log('\n📋 Steps to whitelist your IP in MongoDB Atlas:');
console.log('1. Go to https://cloud.mongodb.com/');
console.log('2. Select your project');
console.log('3. Go to "Network Access" in the left sidebar');
console.log('4. Click "Add IP Address"');
console.log('5. Add the IP address shown above');
console.log('6. Or add 0.0.0.0/0 to allow access from anywhere (less secure)');
console.log('\n⚠️ Note: It may take a few minutes for the changes to take effect.');
}
getAllIPs().catch(console.error);