- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
- Download và Giải nén tập tin File sử dụng Powershell
- [C#] Hướng dẫn cách lấy thông tin đăng nhập tài khoản và mật khẩu web browser trên windows
- [VB.NET] CRUD Thêm xóa sửa tìm kiếm Realtime FireBase
- [C#] Hiển thị thông báo Toast Message trong lập trình Winform
- [C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform
- [C#] Rút gọn đường dẫn link url với TinyURL API
- [C#] Hướng dẫn cách bo tròn winform with Radius
- [C#] Chia sẽ class BackGroundOverlay Show Modal cho Winform
- [C#] Hướng dẫn Flip Image Winform
- [C#] Invoke là gì? cách sử dụng phương thức Invoke()
- [C#] Hướng dẫn chia sẽ file, folder từ ứng dụng sang Zalo Chat
[C#] Đo băng thông, bandwidth, download, ip và upload traffic
Bài viết hôm nay, mình xin hướng dẫn các bạn code C#, cách xem băng thông và tốc độ download và upload của card internet bằng ngôn ngữ C#.
Băng thông (BandWidth) là gì?
Băng thông tên quốc tế là bandwidth. Thuật ngữ này dùng để chỉ lưu lượng của tín hiệu điện được truyền qua thiết bị truyền dẫn trong một giây là bao nhiêu.
Trong lĩnh vực lưu trữ website, thuật ngữ "băng thông" thường được sử dụng để mô tả số lượng dữ liệu tối đa, mà bạn được phép trao đổi (bao gồm upload và download) qua lại giữa website (hoặc server) và người sử dụng trong một đơn vị thời gian (thường là tháng). Tóm lại, băng thông là thông số chỉ dung lượng tối đa mà website của bạn được lưu chuyển qua lại mỗi tháng.
Giao diện demo ứng dụng:
Souce code bandwidth, upload và download bằng C#
using System;
using System.Net.NetworkInformation;
using System.Windows.Forms;
using System.Collections.Generic;
namespace InterfaceTrafficWatch {
public partial class MainForm: Form {
private
const double timerUpdate = 1000;
private NetworkInterface[] nicArr;
private Timer timer;
public MainForm() {
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e) {
InitializeTimer();
}
private void InitializeNetworkInterface() {
nicArr = NetworkInterface.GetAllNetworkInterfaces();
List goodAdapters = new List();
foreach(NetworkInterface nicnac in nicArr) {
if (nicnac.SupportsMulticast && nicnac.GetIPv4Statistics().UnicastPacketsReceived >= 1 && nicnac.OperationalStatus.ToString() == "Up") {
goodAdapters.Add(nicnac.Name);
cmbInterface.Items.Add(nicnac.Name);
}
}
if (goodAdapters.Count != cmbInterface.Items.Count && goodAdapters.Count != 0) {
cmbInterface.Items.Clear();
foreach(string gadpt in goodAdapters) {
cmbInterface.Items.Add(gadpt);
}
cmbInterface.SelectedIndex = 0;
}
if (goodAdapters.Count == 0) cmbInterface.Items.Clear();
}
Initialize the Timer private void InitializeTimer() {
timer = new Timer();
timer.Interval = (int) timerUpdate;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
Update GUI components
for the network interfaces private void UpdateNetworkInterface() {
MessageBox.Show(cmbInterface.Items.Count.ToString());
if (cmbInterface.Items.Count >= 1) {
interface NetworkInterface nic = nicArr[cmbInterface.SelectedIndex];
IPv4InterfaceStatistics interfaceStats = nic.GetIPv4Statistics();
long bytesSentSpeed = (long)(interfaceStats.BytesSent - double.Parse(lblBytesSent.Text)) / 1024;
long bytesReceivedSpeed = (long)(interfaceStats.BytesReceived - double.Parse(lblBytesReceived.Text)) / 1024;
lblSpeed.Text = nic.Speed.ToString();
lblInterfaceType.Text = nic.NetworkInterfaceType.ToString();
lblSpeed.Text = (nic.Speed).ToString("N0");
lblBytesReceived.Text = interfaceStats.BytesReceived.ToString("N0");
lblBytesSent.Text = interfaceStats.BytesSent.ToString("N0");
lblUpload.Text = bytesSentSpeed.ToString() + " KB/s";
lblDownload.Text = bytesReceivedSpeed.ToString() + " KB/s";
UnicastIPAddressInformationCollection ipInfo = nic.GetIPProperties().UnicastAddresses;
foreach(UnicastIPAddressInformation item in ipInfo) {
if (item.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
labelIPAddress.Text = item.Address.ToString();
uniCastIPInfo = item;
break;
}
}
}
}
void timer_Tick(object sender, EventArgs e) {
InitializeNetworkInterface();
UpdateNetworkInterface();
}
}
}
Các bạn có thể download code ở bên dưới để tham khảo.
Have fun :)