可实现本机TCP or udp网络监听
private void btnStart_Click(object sender, EventArgs e) { //开始抓取数据包 if (btnStart.Text == "开始抓取") { //循环抓取每个网卡的数据包 for (int i = 0; i < packetMonitor.Length; i ) { if (cmbIpList.SelectedIndex == 0) { try { //第i个开始抓取 packetMonitor[i].begainMonitor(); } catch { MessageBox.Show("内部错误,请联系管理员"); } } else { try { //抓取指定的Ip packetMonitor[cmbIpList.SelectedIndex - 1].begainMonitor(); } catch { MessageBox.Show("内部错误,请联系管理员"); } } btnStart.Text = "停止抓取"; toolStripStatusLabel1.Text = "开始监测所有端口"; } } //停止抓取 else { for (int i = 0; i < packetMonitor.Length; i ) { packetMonitor[i].Stop(); } btnStart.Text = "开始抓取"; toolStripStatusLabel1.Text = "停止监测"; } }
评论