public Form1() { InitializeComponent(); InitializeBackgroundWorker(); comboBox3.DataSource = Pcap.GetAllDevices(); comboBox3.DisplayMember = "Description"; }
private void FillComboBoxDevices() { // Retrieve the device list and set it as the combo box data source comboBoxDevices.DataSource = Pcap.GetAllDevices(); // Set the combo box display member comboBoxDevices.DisplayMember = "Description"; }
public static void Main(string[] args) { string ver = SharpPcap.Version.VersionString; /* Print SharpPcap version */ Console.WriteLine("SharpPcap {0}, Example2.ArpResolve.cs", ver); Console.WriteLine(); /* Retrieve the device list */ List <PcapDevice> devices = Pcap.GetAllDevices(); /*If no device exists, print error */ if (devices.Count < 1) { Console.WriteLine("No device found on this machine"); return; } Console.WriteLine("The following devices are available on this machine:"); Console.WriteLine("----------------------------------------------------"); Console.WriteLine(); int i = 0; /* Scan the list printing every entry */ foreach (PcapDevice dev in devices) { /* Description */ Console.WriteLine("{0}) {1} {2}", i, dev.Name, dev.Description); i++; } Console.WriteLine(); Console.Write("-- Please choose a device for sending the ARP request: "); i = int.Parse(Console.ReadLine()); string device = devices[i].Name; System.Net.IPAddress ip; while (true) { Console.Write("-- Please enter IP address to be resolved by ARP: "); if (System.Net.IPAddress.TryParse(Console.ReadLine(), out ip)) { break; } Console.WriteLine("Bad IP address format, please try again"); } //Create a new ARP resolver //(for more info, see: //http://www.tamirgal.com/home/SourceView.aspx?Item=SharpPcap&File=ARP.cs) ARP arper = new ARP(device); //print the resolved address Console.WriteLine(ip + " is at: " + arper.Resolve(ip)); }
public static void Run(string[] args) { int lLen = EthernetFields_Fields.ETH_HEADER_LEN; const int MIN_PKT_LEN = 42; byte[] data = System.Text.Encoding.ASCII.GetBytes("HELLO"); byte[] bytes = new byte[MIN_PKT_LEN + data.Length]; Array.Copy(data, 0, bytes, MIN_PKT_LEN, data.Length); List <PcapDevice> devices = Pcap.GetAllDevices(); PcapDevice device = devices[2]; UDPPacket packet = new UDPPacket(lLen, bytes); //Ethernet Fields packet.DestinationHwAddress = PhysicalAddress.Parse("001122334455"); // NOTE: the source hw address will be filled in by the network stack or the // network hardware // packet.SourceHwAddress = device.MacAddress; packet.EthernetProtocol = EthernetPacket.EtherType.IP; //IP Fields packet.DestinationAddress = System.Net.IPAddress.Parse("58.100.187.167"); // NOTE: the source address will be filled in by the network stack based on // the device used for sending // packet.SourceAddress = System.Net.IPAddress.Parse(device.IpAddress); packet.IPProtocol = IPProtocol.IPProtocolType.UDP; packet.TimeToLive = 20; packet.ipv4.Id = 100; packet.IPVersion = IPPacket.IPVersions.IPv4; packet.ipv4.IPTotalLength = bytes.Length - lLen; packet.ipv4.IPHeaderLength = IPv4Fields_Fields.IP_HEADER_LEN; //UDP Fields packet.DestinationPort = 9898; packet.SourcePort = 80; //TODO: checksum methods are disabled due to unfinished ipv4/ipv6 work throw new System.NotImplementedException(); // packet.ComputeIPChecksum(); // packet.ComputeUDPChecksum(); device.Open(); device.SendPacket(packet); device.Close(); }
public void PcapGetAllDevicesTest() { List <PcapDevice> devices = Pcap.GetAllDevices(); if (devices.Count == 0) { Console.WriteLine("No pcap supported devices found, are you running" + " as a user with access to adapters (root on Linux)?"); } else { Console.WriteLine("Found {0} devices", devices.Count); } foreach (PcapDevice d in devices) { Console.WriteLine(d.ToString()); } }
// This starts the capturing public void Start() { // DISABLED return; List <PcapDevice> devices = Pcap.GetAllDevices(); if (devices.Count < 1) { General.Fail("No network devices connected."); return; } // Find the device we want to track traffic on foreach (PcapDevice dev in devices) { // Just pick any device that has an address if (dev.Addresses.Count > 0) { trackdevice = dev; } } string addrstr = ""; for (int i = 0; i < trackdevice.Addresses.Count; i++) { if (trackdevice.Addresses[i].Addr.type != SharpPcap.Containers.Sockaddr.Type.HARDWARE) { if (addrstr.Length > 0) { addrstr += ", "; } addrstr += "'" + trackdevice.Addresses[i].Addr.ipAddress + "'"; } } General.WriteLogLine("Tracking network on device '" + trackdevice.Description.Trim() + "' with address " + addrstr); // Start capturing packets trackdevice.Open(true, 1000); trackdevice.OnPacketArrival += PacketHandler; trackdevice.StartCapture(); }
public static void Main1(string[] args) { string ver = SharpPcap.Version.VersionString; /* Print SharpPcap version */ Console.WriteLine("SharpPcap {0}, SendTcpSynExample.cs", ver); Console.WriteLine(); /* Retrieve the device list */ List <PcapDevice> devices = Pcap.GetAllDevices(); /*If no device exists, print error */ if (devices.Count < 1) { Console.WriteLine("No device found on this machine"); return; } Console.WriteLine("The following devices are available on this machine:"); Console.WriteLine("----------------------------------------------------"); Console.WriteLine(); int i = 0; /* Scan the list printing every entry */ foreach (PcapDevice dev in devices) { /* Description */ Console.WriteLine("{0}) {1}", i, dev.Description); i++; } Console.WriteLine(); Console.Write("-- Please choose a device for sending: "); i = int.Parse(Console.ReadLine()); PcapDevice device = devices[i]; SendTcpSyn(device); }
private void FillComboBoxDevices() { comboBoxDevices.DataSource = Pcap.GetAllDevices(); comboBoxDevices.DisplayMember = "Description"; comboBoxDevices.SelectedIndex = -1; }