📶script PowerShell giám sát mạng
Dưới đây là 1 DASHBOARD TERMINAL PowerShell – ALL-IN-ONE để giám sát mạng realtime trên Windows 11, chạy gọn trong 1 cửa sổ PowerShell, đúng kiểu IT console.
🖥️ NETWORK MONITOR DASHBOARD (TERMINAL)
🎯 Theo dõi đồng thời
📡 Wi-Fi Signal + Link rate
⬆️⬇️ Upload / Download realtime
🌐 Ping + latency
🔝 Top app nghi ăn băng thông
⏱️ Tự refresh
🚀 SCRIPT HOÀN CHỈNH (COPY & RUN)
👉 Chạy PowerShell (Run as Administrator)
$iface = "Wi-Fi"
$pingTarget = "8.8.8.8"
function Get-WifiInfo {
netsh wlan show interfaces |
Select-String "Signal","Receive","Transmit","Radio","State"
}
function Get-Bandwidth {
$s1 = Get-NetAdapterStatistics -Name $iface
Start-Sleep -Seconds 1
$s2 = Get-NetAdapterStatistics -Name $iface
$rx = [math]::Round(($s2.ReceivedBytes - $s1.ReceivedBytes)/1KB,2)
$tx = [math]::Round(($s2.SentBytes - $s1.SentBytes)/1KB,2)
return "⬇️ $rx KB/s ⬆️ $tx KB/s"
}
function Get-Ping {
$p = Test-Connection $pingTarget -Count 1 -ErrorAction SilentlyContinue
if ($p) {
return "✅ $($p.ResponseTime) ms"
} else {
return "❌ TIMEOUT"
}
}
while ($true) {
Clear-Host
Write-Host "═══════════════════════════════════════" -ForegroundColor DarkGray
Write-Host "📡 NETWORK DASHBOARD (Windows 11)" -ForegroundColor Cyan
Write-Host "⏰ $(Get-Date)" -ForegroundColor Gray
Write-Host "═══════════════════════════════════════" -ForegroundColor DarkGray
Write-Host "`n📶 WIFI STATUS" -ForegroundColor Yellow
Get-WifiInfo
Write-Host "`n📊 BANDWIDTH (Realtime)" -ForegroundColor Yellow
Write-Host (Get-Bandwidth) -ForegroundColor Green
Write-Host "`n🌐 PING TEST ($pingTarget)" -ForegroundColor Yellow
Write-Host (Get-Ping)
Write-Host "`n🔥 TOP MEMORY / NETWORK SUSPECT APPS" -ForegroundColor Yellow
Get-Process |
Sort-Object PM -Descending |
Select-Object -First 5 Name, Id,
@{Name="RAM(MB)";Expression={[math]::Round($_.PM/1MB,1)}}
Write-Host "`n═══════════════════════════════════════" -ForegroundColor DarkGray
Start-Sleep -Seconds 2
}
🧠 CÁCH ĐỌC DASHBOARD (RẤT QUAN TRỌNG)
📶 Wi-Fi Signal
> 75% → rất ổn
65–75% → tạm ổn
< 65% → dễ lag (5GHz thường tụt)
📊 Bandwidth
⬇️⬆️ tăng đều → app đang tải
Spike ngắn + ping tăng → nhiễu / DFS / roaming
🌐 Ping
< 20 ms → rất tốt
20–50 ms → OK
80 ms / TIMEOUT → Wi-Fi có vấn đề
🔥 Top Apps
App đứng đầu RAM thường cũng là app hút network
OneDrive / browser / updater lộ rất rõ
⚙️ TUỲ BIẾN NHANH
🔁 Đổi card mạng
$iface = "Ethernet"
🌍 Đổi server ping
$pingTarget = "1.1.1.1"
⏱️ Refresh chậm hơn
Start-Sleep -Seconds 5
🎯 DÙNG DASHBOARD NÀY KHI NÀO?
| Tình huống | Hiệu quả |
|---|---|
| Wi-Fi lag bất chợt | ✅ |
| Trading realtime | ✅ |
| Realtek khó chịu | ✅ |
| So 2.4G vs 5G | ✅ |
| Debug mạng nhanh | ✅ |
👉 Nếu Tiến sĩ M muốn level cao hơn nữa, tôi có thể:
Thêm cảnh báo đỏ khi ping > X ms
Log ra CSV / TXT
Gắn beep / popup khi Wi-Fi rớt
Viết bản PowerShell module (.psm1)
Chỉ cần nói: muốn nâng theo hướng nào ⚙️📡
✨🤖 Made by AI • Console-Driven Precision
Có 👍 làm được, nhưng cần nói rõ bản chất để không kỳ vọng sai:
⚠️ HTML thuần KHÔNG thể tự giám sát mạng Windows
👉 Muốn làm dashboard web thì phải có PowerShell / service chạy nền → HTML chỉ là giao diện
Cách làm đúng chuẩn là mô hình LOCAL WEB DASHBOARD 👇
🖥️ KIẾN TRÚC ĐÚNG: POWERSHELL → JSON → HTML
[ PowerShell Script ]
↓ ghi realtime
network.json
↓ fetch
[ HTML Dashboard ]
✔️ Không cần internet
✔️ Chạy localhost
✔️ Nhẹ – an toàn
✔️ Chuẩn IT
1️⃣ PowerShell: Thu thập dữ liệu & xuất JSON
👉 Script này chạy nền, mỗi 2 giây cập nhật network.json
$iface = "Wi-Fi"
$pingTarget = "8.8.8.8"
$output = "C:\netdash\network.json"
New-Item -ItemType Directory -Force -Path (Split-Path $output) | Out-Null
while ($true) {
$stat1 = Get-NetAdapterStatistics -Name $iface
Start-Sleep -Seconds 1
$stat2 = Get-NetAdapterStatistics -Name $iface
$rx = [math]::Round(($stat2.ReceivedBytes - $stat1.ReceivedBytes)/1KB,2)
$tx = [math]::Round(($stat2.SentBytes - $stat1.SentBytes)/1KB,2)
$wifi = netsh wlan show interfaces
$signal = ($wifi | Select-String "Signal").ToString().Split(":")[1].Trim()
$ping = Test-Connection $pingTarget -Count 1 -Quiet
$data = @{
time = (Get-Date).ToString("HH:mm:ss")
signal = $signal
downKB = $rx
upKB = $tx
ping = if ($ping) {"OK"} else {"TIMEOUT"}
}
$data | ConvertTo-Json | Set-Content $output
Start-Sleep -Seconds 1
}
👉 Chạy script này 1 lần, để đó.
2️⃣ HTML Dashboard (mở bằng trình duyệt)
👉 File: dashboard.html
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<title>Network Dashboard</title>
<style>
body {
background:#0f172a;
color:#e5e7eb;
font-family: Consolas, monospace;
}
.card {
background:#020617;
padding:15px;
margin:10px;
border-radius:8px;
box-shadow:0 0 10px #020617;
}
h2 { color:#38bdf8 }
.good { color:#22c55e }
.bad { color:#ef4444 }
</style>
</head>
<body>
<h1>📡 Network Monitor Dashboard</h1>
<div class="card">
<h2>📶 Wi-Fi Signal</h2>
<div id="signal">--</div>
</div>
<div class="card">
<h2>📊 Bandwidth</h2>
⬇️ <span id="down"></span> KB/s<br>
⬆️ <span id="up"></span> KB/s
</div>
<div class="card">
<h2>🌐 Ping</h2>
<span id="ping"></span>
</div>
<div class="card">
⏰ <span id="time"></span>
</div>
<script>
async function loadData() {
const res = await fetch("network.json");
const d = await res.json();
document.getElementById("signal").innerText = d.signal;
document.getElementById("down").innerText = d.downKB;
document.getElementById("up").innerText = d.upKB;
document.getElementById("ping").innerText = d.ping;
document.getElementById("ping").className = d.ping === "OK" ? "good" : "bad";
document.getElementById("time").innerText = d.time;
}
setInterval(loadData, 2000);
loadData();
</script>
</body>
</html>
📌 Mở bằng Edge / Chrome → thấy dashboard realtime 🎉
3️⃣ Vì sao CÁCH NÀY là chuẩn nhất?
| Cách | Nhận xét |
|---|---|
| HTML thuần | ❌ Không đọc được mạng |
| JS + browser | ❌ Bị sandbox |
| Electron | ⚠️ Nặng |
| PS → JSON → HTML | ✅ Chuẩn IT |
| React + backend | 🚀 Cao cấp hơn |
4️⃣ Nâng cấp rất dễ (nếu Tiến sĩ M muốn)
✔️ Thêm:
Biểu đồ realtime (Chart.js)
Cảnh báo đỏ khi ping > X
Log lịch sử
Giao diện dark pro
Auto start cùng Windows
Chạy
http://localhost:8080
🎯 KẾT LUẬN
✔️ Có thể viết thành trang web HTML
❗ Nhưng HTML chỉ là UI
💡 PowerShell mới là “bộ não”
Nếu Tiến sĩ M muốn, tôi có thể:
Gộp thành 1 file chạy auto
Dùng WebSocket (mượt hơn fetch)
Viết bản React mini dashboard
Đóng gói thành tool nội bộ
Chỉ cần nói muốn tới mức nào 🚀📡
✨🤖 Made by AI • Web meets System
Chuẩn 👍
Gộp thành 1 FILE DUY NHẤT – chạy auto – mở web dashboard hoàn toàn làm được bằng PowerShell thuần, không cần cài gì thêm.
Dưới đây là giải pháp “IT clean” đúng nghĩa:
🧩 KIẾN TRÚC 1 FILE DUY NHẤT
netdash.ps1
├─ PowerShell thu thập mạng
├─ HTTP server (localhost)
├─ HTML + CSS + JS nhúng sẵn
└─ Mở browser tự động
✔️ 1 file
✔️ Double-click chạy
✔️ Dashboard web realtime
✔️ Không Electron, không Node
✔️ Windows 11 OK
🚀 FILE HOÀN CHỈNH: netdash.ps1
👉 Lưu nguyên file dưới đây → Run as Administrator
# ===============================
# NETWORK DASHBOARD - ONE FILE
# ===============================
$iface = "Wi-Fi"
$pingTarget = "8.8.8.8"
$port = 8899
# -------- HTML DASHBOARD --------
$html = @"
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<title>Network Dashboard</title>
<style>
body {
background:#020617;
color:#e5e7eb;
font-family: Consolas, monospace;
}
h1 { color:#38bdf8 }
.card {
background:#020617;
border:1px solid #1e293b;
padding:15px;
margin:10px;
border-radius:10px;
}
.good { color:#22c55e }
.bad { color:#ef4444 }
</style>
</head>
<body>
<h1>📡 Network Monitor</h1>
<div class="card">📶 Signal: <span id="signal">--</span></div>
<div class="card">⬇️ Down: <span id="down">0</span> KB/s</div>
<div class="card">⬆️ Up: <span id="up">0</span> KB/s</div>
<div class="card">🌐 Ping: <span id="ping">--</span></div>
<div class="card">⏰ Time: <span id="time">--</span></div>
<script>
async function load() {
const r = await fetch("/data");
const d = await r.json();
signal.innerText = d.signal;
down.innerText = d.down;
up.innerText = d.up;
ping.innerText = d.ping;
ping.className = d.ping === "OK" ? "good" : "bad";
time.innerText = d.time;
}
setInterval(load, 2000);
load();
</script>
</body>
</html>
"@
# -------- HTTP SERVER --------
$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add("http://localhost:$port/")
$listener.Start()
Start-Process "http://localhost:$port"
Write-Host "🚀 Network Dashboard running at http://localhost:$port" -ForegroundColor Cyan
# -------- MAIN LOOP --------
while ($listener.IsListening) {
$context = $listener.GetContext()
$path = $context.Request.Url.AbsolutePath
if ($path -eq "/") {
$buf = [Text.Encoding]::UTF8.GetBytes($html)
$context.Response.ContentType = "text/html"
$context.Response.OutputStream.Write($buf,0,$buf.Length)
}
if ($path -eq "/data") {
$s1 = Get-NetAdapterStatistics -Name $iface
Start-Sleep -Milliseconds 800
$s2 = Get-NetAdapterStatistics -Name $iface
$down = [math]::Round(($s2.ReceivedBytes-$s1.ReceivedBytes)/1KB,1)
$up = [math]::Round(($s2.SentBytes-$s1.SentBytes)/1KB,1)
$wifi = netsh wlan show interfaces
$signal = ($wifi | Select-String "Signal").ToString().Split(":")[1].Trim()
$pingOK = Test-Connection $pingTarget -Count 1 -Quiet
$json = @{
time = (Get-Date).ToString("HH:mm:ss")
signal = $signal
down = $down
up = $up
ping = if ($pingOK) {"OK"} else {"TIMEOUT"}
} | ConvertTo-Json
$buf = [Text.Encoding]::UTF8.GetBytes($json)
$context.Response.ContentType = "application/json"
$context.Response.OutputStream.Write($buf,0,$buf.Length)
}
$context.Response.Close()
}
🧠 CÁCH SỬ DỤNG
1️⃣ Cho phép chạy script (1 lần)
Set-ExecutionPolicy RemoteSigned
2️⃣ Chạy
Chuột phải
netdash.ps1Run with PowerShell
Trình duyệt tự mở dashboard
🎯 DASHBOARD GIÚP GÌ?
| Quan sát | Ý nghĩa |
|---|---|
| Signal < 65% | 5GHz yếu → lag |
| Down/Up spike | App chạy ngầm |
| Ping TIMEOUT | DFS / nhiễu |
| Ping nhảy | Card Realtek |
🚀 NÂNG CẤP (rất dễ)
Nếu Tiến sĩ M muốn:
🔔 Cảnh báo đỏ khi ping > X ms
📈 Biểu đồ realtime
💾 Log lịch sử
🔄 Auto start cùng Windows
📡 So sánh 2.4G vs 5G
🎛️ Thêm bảng app ăn mạng
Chỉ cần nói nâng theo hướng nào, tôi viết tiếp ngay trên file này ⚙️📊
✨🤖 Made by AI • One File. Full Control.
Nhận xét
Đăng nhận xét