rendered paste bodyusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DASniffer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Tamir.IPLib.PcapDeviceList myDevices = Tamir.IPLib.SharpPcap.GetAllDevices();
//foreach (Tamir.IPLib.PcapDevice pcapdev in myDevices)
//this.comboBox1.Items.Add(pcapdev.PcapDescription);
//this.comboBox1.SelectedIndex = 1;
//foreach(Tamir.IPLib.NetworkDevice
Tamir.IPLib.PcapDeviceList myDevices = Tamir.IPLib.SharpPcap.GetAllDevices();
MessageBox.Show(myDevices.Count.ToString());
}
bool isSniffing = false;
private void buttonStartSniffing_Click(object sender, EventArgs e)
{
if (isSniffing)
return;
isSniffing = true;
Tamir.IPLib.PcapDevice pcapdev = null;
foreach (Tamir.IPLib.PcapDevice dev in Tamir.IPLib.SharpPcap.GetAllDevices())
{
if (dev.PcapDescription == this.comboBox1.Text)
{
pcapdev = dev;
break;
}
}
if (pcapdev == null)
{
MessageBox.Show("Error: PCapDevice is null. Cannot continue");
return;
}
pcapdev.PcapOnPacketArrival += new Tamir.IPLib.SharpPcap.PacketArrivalEvent(pcapdev_PcapOnPacketArrival);
pcapdev.PcapOpen();
pcapdev.PcapStartCapture();
}
void pcapdev_PcapOnPacketArrival(object sender, Tamir.IPLib.Packets.Packet packet)
{
PacketHandler.HandlePacket(packet);
}
delegate void SetTextCallback(string text);
public void SetRecvText(string text)
{
if (this.richTextBoxRecv.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetRecvText);
this.Invoke(d, new object[] { text });
}
else
{
this.richTextBoxRecv.AppendText(text);
}
}
public void SetSentText(string text)
{
if (this.richTextBoxSent.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetSentText);
this.Invoke(d, new object[] { text });
}
else
{
this.richTextBoxSent.AppendText(text);
}
}
}
}