Form1.cs
资源名称:wlll.rar [点击查看]
上传用户:zpsczj
上传日期:2022-02-13
资源大小:4436k
文件大小:12k
源码类别:
网络截获/分析
开发平台:
Visual C++
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Threading;
- using System.Collections;
- using WindowsApplication1;
- namespace wlcs
- {
- public partial class Form1 : Form
- {
- wjian w = new wjian();
- DrawClass dc = new DrawClass();
- public string name;
- public int t, i = 1;
- float s1, s2,s3,s4,s5,s6,p1,p2,p3;
- float[] numbers1 = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0};
- float[] numbers2 = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0 };
- float[] numbers3 = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0 };
- int[] num = new int[] { 0 };
- public Form1()
- {
- InitializeComponent();
- }
- string sec = DateTime.Now.ToString();
- public string shuju1, shuju2, shuju3;
- private void Form1_Load(object sender, EventArgs e)
- {
- this.timer1.Interval = 1000;
- this.timer1.Start();
- this.timer1.Enabled = true;
- string[] instanceNames;
- ArrayList counters = new ArrayList();
- PerformanceCounterCategory mycat1 = new PerformanceCounterCategory("Network Interface");
- try
- {
- instanceNames = mycat1.GetInstanceNames();
- if (instanceNames.Length == 0)
- {
- counters.AddRange(mycat1.GetCounters());
- }
- else
- {
- for (int i = 0; i < instanceNames.Length; i++)
- {
- counters.AddRange(mycat1.GetCounters(instanceNames[i]));
- }
- }
- for (int i = 0; i < instanceNames.Length; i++)
- {
- comboBox1.Items.Add( instanceNames[i]);
- }
- name = instanceNames[0];
- this.performanceCounter1.InstanceName = name;
- this.performanceCounter2.InstanceName = name;
- this.performanceCounter3.InstanceName = name;
- foreach (PerformanceCounter counter in counters)
- {
- Console.WriteLine(counter.CounterName);
- }
- }
- catch (Exception)
- {
- Console.WriteLine("Unable to list the counters for this category");
- }
- comboBox4.Text = Convert.ToString(20);
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- float sulv1 = (float)this.performanceCounter1.NextValue();
- this.toolStripLabel2.Text = "下载速率" + sulv1 / 1024 + "KB/s";
- float sulv2 = (float)this.performanceCounter2.NextValue();
- this.toolStripLabel3.Text = "上传速率" + sulv2 / 1024 + "KB/s";
- float sulv3 = (float)this.performanceCounter3.NextValue();
- this.toolStripLabel4.Text = "总速率" + sulv3 / 1024 + "KB/s";
- t = t + 1;
- s1 = s1 + sulv3 / 1024;
- s3 = s3 + sulv2 / 1024;
- s5 = s5 + sulv1 / 1024;
- if (i > 0)
- {
- numbers1[19] = numbers1[18];
- numbers1[18] = numbers1[17];
- numbers1[17] = numbers1[16];
- numbers1[16] = numbers1[15];
- numbers1[15] = numbers1[14];
- numbers1[14] = numbers1[13];
- numbers1[13] = numbers1[12];
- numbers1[12] = numbers1[11];
- numbers1[11] = numbers1[10];
- numbers1[10] = numbers1[9];
- numbers1[9] = numbers1[8];
- numbers1[8] = numbers1[7];
- numbers1[7] = numbers1[6];
- numbers1[6] = numbers1[5];
- numbers1[5] = numbers1[4];
- numbers1[4] = numbers1[3];
- numbers1[3] = numbers1[2];
- numbers1[2] = numbers1[1];
- numbers1[1] = numbers1[0];
- numbers1[0] = sulv1/1024;
- numbers2[19] = numbers2[18];
- numbers2[18] = numbers2[17];
- numbers2[17] = numbers2[16];
- numbers2[16] = numbers2[15];
- numbers2[15] = numbers2[14];
- numbers2[14] = numbers2[13];
- numbers2[13] = numbers2[12];
- numbers2[12] = numbers2[11];
- numbers2[11] = numbers2[10];
- numbers2[10] = numbers2[9];
- numbers2[9] = numbers2[8];
- numbers2[8] = numbers2[7];
- numbers2[7] = numbers2[6];
- numbers2[6] = numbers2[5];
- numbers2[5] = numbers2[4];
- numbers2[4] = numbers2[3];
- numbers2[3] = numbers2[2];
- numbers2[2] = numbers2[1];
- numbers2[1] = numbers2[0];
- numbers2[0] = sulv2/1024;
- numbers3[19] = numbers3[18];
- numbers3[18] = numbers3[17];
- numbers3[17] = numbers3[16];
- numbers3[16] = numbers3[15];
- numbers3[15] = numbers3[14];
- numbers3[14] = numbers3[13];
- numbers3[13] = numbers3[12];
- numbers3[12] = numbers3[11];
- numbers3[11] = numbers3[10];
- numbers3[10] = numbers3[9];
- numbers3[9] = numbers3[8];
- numbers3[8] = numbers3[7];
- numbers3[7] = numbers3[6];
- numbers3[6] = numbers3[5];
- numbers3[5] = numbers3[4];
- numbers3[4] = numbers3[3];
- numbers3[3] = numbers3[2];
- numbers3[2] = numbers3[1];
- numbers3[1] = numbers3[0];
- numbers3[0] = sulv3 / 1024;
- pictureBox1.Image = Image.FromStream(dc.draw(numbers1, numbers2, numbers3));
- }
- if (t == Convert.ToInt16(comboBox4.Text))
- {
- if (i == 1)
- {
- listBox1.Items.Add("第1次" + " " + s5 / t + "KB/s" + " " + s3 / t + "KB/s" + " " + s1 / t + "KB/s");
- s2 = s1;
- s4 = s3;
- s6 = s5;
- p1 = s1 / t;
- p2 = s3 / t;
- p3 = s5 / t;
- t = 0;
- s1 = 0;
- s3 = 0;
- s5 =0;
- i++;
- shuju1 += this.p1.ToString()+" ";
- shuju2 += this.p2.ToString() + " ";
- shuju3 += this.p3.ToString() + " ";
- }
- else
- {
- listBox1.Items.Add("第" + i + "次" + " " + s5 / t + "KB/s" + " " + s3 / t + "KB/s" + " " + s1 / t + "KB/s");
- listBox1.Items.Add("流量增加" + " " + (s5 - s6) / t + "KB/s" + " " + (s3 - s4) / t + "KB/s" + " " + (s1 - s2) / t + "KB/s");
- s2 = s1;
- s4 = s3;
- s6 = s5;
- p1 = s1 / t;
- p2 = s3 / t;
- p3 = s5 / t;
- t = 0;
- s1 = 0;
- s3 = 0;
- s5 = 0;
- i++;
- shuju1 += this.p1.ToString() + " ";
- shuju2 += this.p2.ToString() + " ";
- shuju3 += this.p3.ToString() + " ";
- }
- }
- if (this.performanceCounter4.CategoryName == this.comboBox3.Text.ToString())
- {
- float sulv4 = (float)this.performanceCounter4.NextValue();
- this.textBox1 .Text = sulv4 + "B/s";
- }
- else
- if (this.performanceCounter5.CategoryName == this.comboBox3.Text.ToString())
- {
- float sulv4 = (float)this.performanceCounter5.NextValue();
- this.textBox1.Text = sulv4 + "B/s";
- }
- else
- if (this.performanceCounter6.CategoryName == this.comboBox3.Text.ToString())
- {
- float sulv4 = (float)this.performanceCounter6.NextValue();
- this.textBox1.Text = sulv4 + "B/s";
- }
- else
- if (this.performanceCounter7.CategoryName == this.comboBox3.Text.ToString())
- {
- float sulv4 = (float)this.performanceCounter6.NextValue();
- this.textBox1.Text = sulv4 + "B/s";
- }
- }
- private void 开始ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.performanceCounter1.InstanceName = this.comboBox1.Text.ToString();
- this.performanceCounter2.InstanceName = this.comboBox1.Text.ToString();
- this.performanceCounter3.InstanceName = this.comboBox1.Text.ToString();
- float sulv1 = (float)this.performanceCounter1.NextValue();
- this.toolStripLabel2.Text = "下载速率" + sulv1 / 1024 + "KB/s";
- float sulv2 = (float)this.performanceCounter2.NextValue();
- this.toolStripLabel3.Text = "上传速率" + sulv2 / 1024 + "KB/s";
- float sulv3 = (float)this.performanceCounter3.NextValue();
- this.toolStripLabel4.Text = "总速率" + sulv3 / 1024 + "KB/s";
- t = 0;
- }
- private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string sd = DateTime.Now.ToString();
- richTextBox1.Text += "本次保存开始时间:" + sec.ToString() +" "+this.comboBox4.Text+"秒内"+ "n" + "下载平均速率" + shuju3 + "n" + "上传平均速率" + shuju2 + "n" + "总平均速率" + shuju1 + "n结束时间:" + sd.ToString() + "n";
- richTextBox1.SaveFile("..//Debug//wenjian.txt..", RichTextBoxStreamType.PlainText);
- }
- private void toolStripButton1_Click(object sender, EventArgs e)
- {
- string sd = DateTime.Now.ToString();
- richTextBox1.Text += "本次保存开始时间:" + sec.ToString() + " " + this.comboBox4.Text + "秒内" + "n" + "下载平均速率" + shuju3 + "n" + "上传平均速率" + shuju2 + "n" + "总平均速率" + shuju1 + "n结束时间:" + sd.ToString() + "n";
- richTextBox1.SaveFile("..//Debug//wenjian.txt..", RichTextBoxStreamType.PlainText);
- }
- private void toolStripButton5_Click(object sender, EventArgs e)
- {
- this.performanceCounter1.InstanceName = this.comboBox1.Text.ToString();
- this.performanceCounter2.InstanceName = this.comboBox1.Text.ToString();
- this.performanceCounter3.InstanceName = this.comboBox1.Text.ToString();
- float sulv1 = (float)this.performanceCounter1.NextValue();
- this.toolStripLabel2.Text = "下载速率" + sulv1 / 1024 + "KB/s";
- float sulv2 = (float)this.performanceCounter2.NextValue();
- this.toolStripLabel3.Text = "上传速率" + sulv2 / 1024 + "KB/s";
- float sulv3 = (float)this.performanceCounter3.NextValue();
- this.toolStripLabel4.Text = "总速率" + sulv3 / 1024 + "KB/s";
- t = 0;
- }
- }
- }