feat(MikrotikTools): enhance traceroute output with reverse DNS support and improved IP handling
Publish Fast Tabler Docker image / build-and-push-fast (push) Failing after 2m28s

This commit is contained in:
2026-02-12 16:14:06 +07:00
parent 1e28fa33f5
commit 635b791118
2 changed files with 33 additions and 18 deletions
+13 -2
View File
@@ -705,6 +705,9 @@ async function tracerouteViaGateway(req, res) {
if (!Number.isFinite(countNum) || countNum <= 0) countNum = 1;
body.count = countNum;
// Включаем reverse DNS (как use-dns=yes), чтобы видеть имена
body['use-dns'] = 'yes';
const hopsNum = Number(maxHops);
if (Number.isFinite(hopsNum) && hopsNum > 0) {
body['max-hops'] = hopsNum;
@@ -744,7 +747,13 @@ async function tracerouteViaGateway(req, res) {
const seen = new Set();
for (const r of rows) {
const host = r.host || r.address || '';
const ip = (r.address && String(r.address).trim()) || '';
const hostField = (r.host && String(r.host).trim()) || '';
// Если host есть и отличается от IP, считаем его DNS-именем,
// иначе всё, что есть, считаем IP.
const dns = hostField && hostField !== ip ? hostField : '';
const host = dns || ip;
// Пропускаем полностью пустые строки без адреса и статуса
if (!host && !r.status) continue;
@@ -758,7 +767,9 @@ async function tracerouteViaGateway(req, res) {
hops.push({
hop: null, // заполним ниже последовательной нумерацией
host,
host, // отображаемое значение по умолчанию
ip: ip || null,
dns: dns || null,
avgMs: parseMs(avgField),
bestMs: parseMs(r.best || r['best-rtt'] || r['min-rtt']),
worstMs: parseMs(r.worst || r['worst-rtt'] || r['max-rtt']),
+20 -16
View File
@@ -270,15 +270,17 @@ function MikrotikTools() {
</tr>
</thead>
<tbody>
{hops.map((h) => (
<tr key={h.hop || `${h.host}-${Math.random()}`}>
{hops.map((h) => {
const ip = h.ip || '';
const dns = h.dns || '';
const mainLabel = dns
? `${dns}${ip ? ` (${ip})` : ''}`
: (ip || h.host || '—');
return (
<tr key={h.hop || `${ip || h.host}-${Math.random()}`}>
<td>{h.hop}</td>
<td>
{h.host || '—'}
{h._label && (
<div className="text-muted small">{h._label}</div>
)}
</td>
<td>{mainLabel}</td>
<td>{h.avgMs != null ? h.avgMs.toFixed(1) : '—'}</td>
<td>
{h.bestMs != null ? h.bestMs.toFixed(1) : '—'} /{' '}
@@ -287,7 +289,7 @@ function MikrotikTools() {
<td>{h.loss != null ? `${h.loss}%` : '—'}</td>
<td>{h.status || '—'}</td>
</tr>
))}
);})}
</tbody>
</table>
</div>
@@ -344,11 +346,13 @@ function buildTracerouteAnalysis(hops, networkConfig, servers, target) {
let worstLatencyHop = null;
hops.forEach((hop, index) => {
const host = hop.host || hop.address || '';
const ip = hop.ip || hop.host || hop.address || '';
const dns = hop.dns || null;
const hostDisplay = dns ? `${dns}${ip ? ` (${ip})` : ''}` : (ip || hop.host || '');
const avg = hop.avgMs;
const loss = hop.loss;
let descr = `Хоп ${hop.hop || index + 1}: ${host || 'неизвестный узел'}`;
let descr = `Хоп ${hop.hop || index + 1}: ${hostDisplay || 'неизвестный узел'}`;
const details = [];
if (avg != null) details.push(`среднее время ≈ ${avg.toFixed(1)} мс`);
@@ -357,15 +361,15 @@ function buildTracerouteAnalysis(hops, networkConfig, servers, target) {
}
if (loss != null) details.push(`потеря пакетов ${loss}%`);
// Привязка к gateway
const gw = gateways.find((g) => g.ip && g.ip === host);
// Привязка к gateway (по IP)
const gw = gateways.find((g) => g.ip && g.ip === ip);
if (gw) {
const srvLabel = findServerLabel(gw.serverId);
details.push(`gateway "${gw.description || gw.ip}" на сервере ${srvLabel || gw.serverId}`);
}
// Привязка к туннельному интерфейсу
const iface = ifaces.find((i) => i.localIp === host || i.remoteIp === host);
// Привязка к туннельному интерфейсу (по IP)
const iface = ifaces.find((i) => i.localIp === ip || i.remoteIp === ip);
if (iface) {
const s1 = findServerLabel(iface.serverId);
const s2 = findServerLabel(iface.serverId2);
@@ -407,7 +411,7 @@ function buildTracerouteAnalysis(hops, networkConfig, servers, target) {
if (firstTimeoutHop) {
lines.push(
`Начиная с хопа ${firstTimeoutHop.hop} (${firstTimeoutHop.host || 'неизвестный узел'}) наблюдаются таймауты — цель может быть недоступна или где-то по пути фильтруется ICMP.`
`Начиная с хопа ${firstTimeoutHop.hop} (${firstTimeoutHop.dns ? `${firstTimeoutHop.dns}${firstTimeoutHop.ip ? ` (${firstTimeoutHop.ip})` : ''}` : (firstTimeoutHop.ip || firstTimeoutHop.host || 'неизвестный узел')}) наблюдаются таймауты — цель может быть недоступна или где-то по пути фильтруется ICMP.`
);
} else {
lines.push('Таймаутов или явной потери пакетов по пути не обнаружено (по данным MikroTik).');