1const https = require('https');
2const { URL } = require('url');
4require('dotenv').config();
6const MESHCENTRAL_URL = process.env.MESHCENTRAL_URL;
7const USERNAME = process.env.MESHCENTRAL_USERNAME;
8const PASSWORD = process.env.MESHCENTRAL_PASSWORD;
13async function login() {
14 const loginUrl = new URL('/login', MESHCENTRAL_URL);
16 const postData = `action=login&username=${encodeURIComponent(USERNAME)}&password=${encodeURIComponent(PASSWORD)}&token=`;
21 'Content-Type': 'application/x-www-form-urlencoded',
22 'Content-Length': Buffer.byteLength(postData)
26 return new Promise((resolve, reject) => {
27 const req = https.request(loginUrl, options, (res) => {
30 if (res.headers['set-cookie']) {
31 const cookies = res.headers['set-cookie'];
32 for (const c of cookies) {
33 if (c.startsWith('xid=')) {
34 cookie = c.split(';')[0];
41 res.on('data', chunk => data += chunk);
42 res.on('end', () => resolve(cookie));
45 req.on('error', reject);
56async function getPage(path, cookie) {
57 const url = new URL(path, MESHCENTRAL_URL);
62 'User-Agent': 'Mozilla/5.0'
66 return new Promise((resolve, reject) => {
67 https.get(url, options, (res) => {
69 res.on('data', chunk => data += chunk);
70 res.on('end', () => resolve(data));
71 }).on('error', reject);
78async function main() {
80 console.log('š§ Logging in to MeshCentral...\n');
82 const cookie = await login();
84 throw new Error('Login failed - no cookie received');
87 console.log('ā
Login successful\n');
89 // Try to get the main page
90 console.log('š Fetching main page...\n');
91 const html = await getPage('/', cookie);
93 // Look for device references in the HTML
94 const deviceMatches = html.match(/node\/[a-zA-Z0-9\/_-]+/g) || [];
95 const uniqueDevices = [...new Set(deviceMatches)];
97 console.log(`ā
Found ${uniqueDevices.length} device reference(s):\n`);
98 uniqueDevices.forEach(device => {
99 console.log(` - ${device}`);
102 // Also look for mesh references
103 const meshMatches = html.match(/mesh\/[a-zA-Z0-9\/_-]+/g) || [];
104 const uniqueMeshes = [...new Set(meshMatches)];
106 console.log(`\nā
Found ${uniqueMeshes.length} mesh reference(s):\n`);
107 uniqueMeshes.forEach(mesh => {
108 console.log(` - ${mesh}`);
112 const ipMatches = html.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g) || [];
113 const uniqueIps = [...new Set(ipMatches)];
115 if (uniqueIps.length > 0) {
116 console.log(`\nš Found ${uniqueIps.length} IP address(es):\n`);
117 uniqueIps.forEach(ip => {
118 console.log(` - ${ip}`);
123 console.error('ā Error:', error.message);