using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace Network_Traffic
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
int iInterfaceNum;
int iFrequency;
double dBytesReceived;
double dBytesSent;
private void btnStart_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
if (txtAdapter.Text == "")
{
MessageBox.Show("Type a network adapter number into the text box.", "No Input",
MessageBoxButtons.OK, MessageBoxIcon.Information);
txtAdapter.Focus();
txtAdapter.SelectAll();
}
if (txtFrequency.Text == "")
{
MessageBox.Show("Type a frequency value into the text box.", "No Input",
MessageBoxButtons.OK, MessageBoxIcon.Information);
txtFrequency.Focus();
txtFrequency.SelectAll();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
iInterfaceNum = Convert.ToInt32(txtAdapter.Text);
iFrequency = Convert.ToInt32(txtFrequency.Text);
if (rdoReceived.Checked == true)
{
dBytesReceived = interfaces[iInterfaceNum].GetIPv4Statistics().BytesReceived;
dBytesReceived.ToString(lstData.Text);
}
else
{
dBytesSent = interfaces[iInterfaceNum].GetIPv4Statistics().BytesSent;
dBytesSent.ToString(lstData.Text);
}
}
private void btnStop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
}
}