Network Traffic Monitor
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1

Thread: Network Traffic Monitor

  1. #1
    Join Date
    Mar 2010

    Network Traffic Monitor

    Hey guys, a programming noob here so go easy on me please! LOL

    I could really do with some help. I have been asked to create a Windows Forms Application using C# that can monitor network traffic (bytes received and sent) within a specified time interval. I really have tried but I've reached a dead end and really don't know where to go next.

    If anyone could look over this code and tell me the errors of my ways and how to get the **** thing working I'd be most grateful!

    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()

    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);

    if (txtFrequency.Text == "")
    MessageBox.Show("Type a frequency value into the text box.", "No Input",
    MessageBoxButtons.OK, MessageBoxIcon.Information);


    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;

    dBytesSent = interfaces[iInterfaceNum].GetIPv4Statistics().BytesSent;

    private void btnStop_Click(object sender, EventArgs e)
    timer1.Enabled = false;

    I've also attached the project!

    Again, I'm new to programming so please bear that in mind, but please do help me!
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center