diff --git a/backend/routes/mikrotikConfigRoutes.js b/backend/routes/mikrotikConfigRoutes.js index ffb30c6..9824726 100644 --- a/backend/routes/mikrotikConfigRoutes.js +++ b/backend/routes/mikrotikConfigRoutes.js @@ -393,21 +393,28 @@ async function pingViaInterface(req, res) { } // 4) Последний фоллбек: если ifaceName до сих пор не определён, - // пробуем взять первый интерфейс, имя которого начинается с "ether" - // (обычно это основной WAN/LAN-порт). + // пробуем взять первый физический порт ether1/ether2 (если есть), + // иначе любой интерфейс с префиксом "ether". if (!ifaceName) { try { const ifRes = await client.command('interface/print', { '.proplist': ['name'], - '.query': ['name~^ether'], }); const data = ifRes?.data; const interfaces = Array.isArray(data) ? data : (data ? [data] : []); - const firstEther = interfaces.find( - (it) => typeof it.name === 'string' && it.name.toLowerCase().startsWith('ether'), - ); - if (firstEther && typeof firstEther.name === 'string') { - ifaceName = firstEther.name; + const names = interfaces + .map((it) => (typeof it.name === 'string' ? it.name : null)) + .filter(Boolean); + + let candidate = null; + if (names.includes('ether1')) candidate = 'ether1'; + else if (names.includes('ether2')) candidate = 'ether2'; + else { + candidate = names.find((n) => n.toLowerCase().startsWith('ether')) || null; + } + + if (candidate) { + ifaceName = candidate; } } catch (_) { // Если не получилось прочитать интерфейсы — просто продолжаем без interface.