'use strict'; const API = 'https://d5dkci5hnpjk6lv4slb5.d8epmcec.apigw.yandexcloud.net/api/packet-path'; const DNS_API = 'https://cloudflare-dns.com/dns-query'; const state = { localIp: '192.168.x.x', publicIp: '', running: false, }; // ===== DOM ===== const $ = (sel) => document.querySelector(sel); const visual = $('#pktVisual'); const logEl = $('#pktLog'); const startBtn = $('#pktStart'); const domainInput = $('#pktDomain'); // ===== Logging ===== function addLog(text, cls = '') { const line = document.createElement('p'); line.className = 'pkt-log-line ' + cls; line.textContent = text; logEl.appendChild(line); logEl.scrollTop = logEl.scrollHeight; } function clearLog() { logEl.innerHTML = ''; } // ===== Get local IP via WebRTC (2 метода) ===== async function getLocalIp() { // Метод 1: без STUN — работает на десктопе, возвращает только локальный IP try { const pc = new RTCPeerConnection({ iceServers: [] }); pc.createDataChannel(''); const offer = await pc.createOffer(); await pc.setLocalDescription(offer); const result = await new Promise((resolve) => { const timeout = setTimeout(() => { pc.close(); resolve(null); }, 3000); pc.onicecandidate = (e) => { if (!e || !e.candidate || !e.candidate.candidate) return; const parts = e.candidate.candidate.split(' '); if (parts.length >= 4) { const ip = parts[4]; if (/^192\.168\.\d+\.\d+$/.test(ip) || /^10\.\d+\.\d+\.\d+$/.test(ip) || /^172\.(1[6-9]|2\d|3[01])\.\d+\.\d+$/.test(ip)) { clearTimeout(timeout); pc.close(); resolve(ip); return; } } }; }); if (result) return result; } catch (e) { // Метод 1 не сработал — пробуем со STUN } // Метод 2: со STUN — работает на Android, но может быть заблокирован на десктопе try { const config = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }; const pc = new RTCPeerConnection(config); pc.createDataChannel(''); const offer = await pc.createOffer(); await pc.setLocalDescription(offer); return new Promise((resolve) => { const timeout = setTimeout(() => { pc.close(); resolve(null); }, 4000); pc.onicecandidate = (e) => { if (!e || !e.candidate || !e.candidate.candidate) return; const parts = e.candidate.candidate.split(' '); if (parts.length >= 4) { const ip = parts[4]; if (/^192\.168\.\d+\.\d+$/.test(ip) || /^10\.\d+\.\d+\.\d+$/.test(ip) || /^172\.(1[6-9]|2\d|3[01])\.\d+\.\d+$/.test(ip)) { clearTimeout(timeout); pc.close(); resolve(ip); return; } } }; }); } catch (err) { return null; } } // ===== Generate fake local IP (fallback) ===== function generateLocalIp() { const ranges = [ () => '192.168.' + Math.floor(Math.random() * 256) + '.' + Math.floor(Math.random() * 254 + 1), () => '10.' + Math.floor(Math.random() * 256) + '.' + Math.floor(Math.random() * 256) + '.' + Math.floor(Math.random() * 254 + 1), () => '172.' + (16 + Math.floor(Math.random() * 16)) + '.' + Math.floor(Math.random() * 256) + '.' + Math.floor(Math.random() * 254 + 1), ]; return ranges[Math.floor(Math.random() * ranges.length)](); } // ===== Get public IP via ipify.org ===== async function getPublicIp() { try { const resp = await fetch('https://api.ipify.org?format=json'); const data = await resp.json(); return data.ip || null; } catch (e) { return null; } } // ===== DNS via Cloudflare DoH ===== async function resolveDns(domain) { const url = DNS_API + '?name=' + encodeURIComponent(domain) + '&type=A'; const resp = await fetch(url, { headers: { accept: 'application/dns-json' }, }); const data = await resp.json(); if (data.Answer && data.Answer.length > 0) { return data.Answer[0].data; } return null; } // ===== Check blocked IP ===== function isBlockedIp(ip) { const prefixes = [ '93.158.134', '93.158.135', '2.18.57', '195.34.32', '185.167', '77.88.8', '5.255.254', '5.255.255', ]; for (const p of prefixes) { if (ip.startsWith(p)) return true; } const parts = ip.split('.'); if (parts.length === 4 && parts[0] === '5' && parts[1] === '255') return true; return false; } // ===== API call с таймаутом ===== async function apiCall(params, timeoutMs = 5000) { const url = API + '?' + new URLSearchParams(params).toString(); const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeoutMs); try { const resp = await fetch(url, { signal: controller.signal }); return await resp.json(); } finally { clearTimeout(timer); } } // ===== Генератор реалистичного маршрута ===== function generateRealisticHops(domain, targetIp, publicIp) { // Парсим целевой IP для генерации реалистичных промежуточных адресов const targetParts = targetIp.split('.').map(Number); // Генерируем псевдослучайное число на основе домена (детерминированно) let seed = 1; for (let i = 0; i < domain.length; i++) { seed = ((seed << 5) - seed) + domain.charCodeAt(i); seed = seed & 0x7FFFFFFF; // Convert to positive 31bit integer } if (seed === 0) seed = 1; function seededRandom() { seed = (seed * 16807) % 2147483647; return (seed - 1) / 2147483646; } // Типичные российские провайдеры (начальные октеты) const providerRanges = [ { name: 'Дом.ру', range: '62.75', city: 'Москва', country: 'Россия' }, { name: 'МТС', range: '178.176', city: 'Москва', country: 'Россия' }, { name: 'Билайн', range: '95.163', city: 'Москва', country: 'Россия' }, { name: 'Мегафон', range: '37.110', city: 'Москва', country: 'Россия' }, { name: 'Энфорта', range: '91.216', city: 'Екатеринбург', country: 'Россия' }, { name: 'ТСДТ', range: '195.208', city: 'Саратов', country: 'Россия' }, ]; // Точки обмена трафиком (IXP) const ixpRanges = [ { name: 'MSK-IX', range: '195.34', city: 'Москва', country: 'Россия' }, { name: 'NTC-IX', range: '194.58', city: 'Москва', country: 'Россия' }, { name: 'Regru', range: '195.133', city: 'Москва', country: 'Россия' }, ]; // Транзитные провайдеры const transitRanges = [ { name: 'DSNET', range: '195.36', city: 'Москва', country: 'Россия' }, { name: 'Selectel', range: '188.120', city: 'Санкт-Петербург', country: 'Россия' }, { name: 'Timeweb', range: '194.85', city: 'Новосибирск', country: 'Россия' }, { name: 'Yandex Cloud', range: '5.255', city: 'Москва', country: 'Россия' }, { name: 'MTS-Megefon', range: '5.188', city: 'Москва', country: 'Россия' }, ]; // Выбираем провайдера на основе seed const provider = providerRanges[Math.floor(seededRandom() * providerRanges.length)]; // Генерируем hops const hops = []; const hopCount = 6 + Math.floor(seededRandom() * 5); // 6-10 хопов // Хоп 1: домашний роутер hops.push({ hop: 1, hosts: [{ ip: '192.168.1.1', latency: Math.floor(seededRandom() * 2) + 1 }], timeouts: 0, label: 'Домашний роутер' }); // Хоп 2: провайдер доступа const providerIp = provider.range + '.' + Math.floor(seededRandom() * 255) + '.' + Math.floor(seededRandom() * 255); hops.push({ hop: 2, hosts: [{ ip: providerIp, latency: Math.floor(seededRandom() * 10) + 3 }], timeouts: 0, label: 'Провайдер (' + provider.name + ')', geo: provider.city + ', ' + provider.country }); // Промежуточные хопы (IXP + транзит) const mix = [...ixpRanges, ...transitRanges]; for (let i = 0; i < hopCount - 3; i++) { const node = mix[Math.floor(seededRandom() * mix.length)]; const ip = node.range + '.' + Math.floor(seededRandom() * 255) + '.' + Math.floor(seededRandom() * 255); const latency = 5 + Math.floor(seededRandom() * 30) + i * 3; hops.push({ hop: i + 3, hosts: [{ ip: ip, latency: latency }], timeouts: 0, label: node.name, geo: node.city + ', ' + node.country }); } // Последний хоп: целевой сервер const lastHopNum = hopCount; hops.push({ hop: lastHopNum, hosts: [{ ip: targetIp, latency: 20 + Math.floor(seededRandom() * 80) }], timeouts: 0, label: domain }); return hops; } // ===== Add node to visual path ===== function addNodeToVisual(name, detail, geo = '') { // Remove placeholder if present const placeholder = visual.querySelector('p'); if (placeholder) placeholder.remove(); // If no path container, create one let path = visual.querySelector('.pkt-path'); if (!path) { path = document.createElement('div'); path.className = 'pkt-path'; visual.appendChild(path); } // Add arrow between nodes const nodes = path.querySelectorAll('.pkt-node'); if (nodes.length > 0) { const arrow = document.createElement('div'); arrow.className = 'pkt-arrow pkt-arrow-anim'; arrow.textContent = '\u2192'; path.appendChild(arrow); } // Create node const node = document.createElement('div'); node.className = 'pkt-node pkt-node-appear'; let html = '
Введи доменное имя и нажми «Найти путь»
'; clearLog(); }; visual.appendChild(resetBtn); state.running = false; startBtn.disabled = false; } // ===== Start button ===== startBtn.addEventListener('click', () => { const domain = domainInput.value.trim().toLowerCase(); if (!domain) { domainInput.focus(); return; } runPacketPath(domain); }); // ===== Enter key ===== domainInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') startBtn.click(); }); // ===== Init ===== (function init() { // Ничего не нужно инициализировать })();