Network Traffic Monitoring Program

Source: Internet
Author: User

Upload an image first.

Implementation Method:

ThisProgramWMI is used to dynamically obtain data in WMI. And the calculated results are displayed on the interface.

The main WMI classes used are win32_perfrawdata_tcpip_networkinterface and win32_networkadapter.

First, use win32_networkadapter to obtain the names of all network adapters in the computer. After selecting different names, you can dynamically obtain the underlying information.

The method for obtaining an adapter on a computer is as follows:

Ilist <win32_networkadapter> networditems = NULL;
Networkadapter NA = NULL;
NA = new networkadapter (computername );
Networditems = Na. selectall ();

Foreach (win32_networkadapter item in networditems)
{
String S = item. adaptertype;
If (s! = NULL)
{
If (item. servicename = "pptpminiport ")
{
Continue;
}
Upnetitems (item. netconnectionid, item. Name );
}
}

Main Computing speedAlgorithmAs follows:

PNI. m_where = "where name = '" + Result + "'";
Netlist. Clear ();
Netlist = PNI. selectall ();
Win32_perfrawdata_tcpip_networkinterface item = netlist [0] As win32_perfrawdata_tcpip_networkinterface;

Float countervalue1 = (float) item. bytesreceivedpersec;
Float upv1 = (float) item. bytessentpersec;
Float timevaluee1 = (float) item. timestamp_perftime;
Float timebase = (float) item. frequency_perftime;
System. Threading. thread. Sleep (500 );

Netlist. Clear ();
Netlist = PNI. selectall ();
Item = netlist [0] As win32_perfrawdata_tcpip_networkinterface;

Float countervalue2 = (float) item. bytesreceivedpersec;
Float upv2 = (float) item. bytessentpersec;

Float timevalue2 = (float) item. timestamp_perftime;

If (timevalue2-timevalue1 = 0)
{}
Else
{
Float downs = (countervalue2-countervalue1)/(timevalue2-timevalue1)/timebase)/1024;
Float up = (upv2-upv1)/(timevalue2-timevalue1)/timebase)/1024;
Updatavalue (downs );
Updatavalue2 (up );

}

 

This program uses an easywmi DLL, which includes all WMI definitions. You can search for and download the code from codeproject.

WMI is very powerful, and information on almost all computers can be found through this. It is easy to develop performance monitoring programs. In the future, you will have time to write a program that uses WMI for computer monitoring and management.

However, I have been busy writing a com program with UI EXE using VC recently. There may be no time in the recent period.

 

Very late, sleeping

Corresponding controls: http://www.codeproject.com/Articles/17564/Simple-Performance-Chart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.