1const MeshCentralAPI = require('./lib/meshcentral-api.js');
2require('dotenv').config();
4const api = new MeshCentralAPI({
5 url: process.env.MESHCENTRAL_URL,
6 username: process.env.MESHCENTRAL_USERNAME,
7 password: process.env.MESHCENTRAL_PASSWORD
13async function main() {
15 console.log('š Logging in to MeshCentral...');
18 console.log('š” Scraping device list from web interface...');
19 const html = await api._request('GET', '/');
21 // Extract node IDs from the HTML
22 const nodeMatches = html.match(/node\/[a-zA-Z0-9\/_-]+/g) || [];
23 const uniqueNodes = [...new Set(nodeMatches)];
25 if (uniqueNodes.length === 0) {
26 console.log('ā No devices found. Make sure the MeshAgent is running and connected.');
30 console.log(`\nā
Found ${uniqueNodes.length} device(s):\n`);
31 uniqueNodes.forEach((nodeId, index) => {
32 console.log(`${index + 1}. ${nodeId}`);
35 // Try to get more details for the first device
36 if (uniqueNodes.length > 0) {
37 console.log('\nš First device details:');
38 console.log('Node ID:', uniqueNodes[0]);
39 console.log('\nUse this node ID to link to agent_id 115');
43 console.error('ā Error:', error.message);