// Print all the available information on the given interface private static void DevicePrint(IPacketDevice device) { // Name Console.WriteLine(device.Name); // Description if (device.Description != null) Console.WriteLine("\tDescription: " + device.Description); // Loopback Address Console.WriteLine("\tLoopback: " + (((device.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback) ? "yes" : "no")); // IP addresses foreach (DeviceAddress address in device.Addresses) { Console.WriteLine("\tAddress Family: " + address.Address.Family); if (address.Address != null) Console.WriteLine(("\tAddress: " + address.Address)); if (address.Netmask != null) Console.WriteLine(("\tNetmask: " + address.Netmask)); if (address.Broadcast != null) Console.WriteLine(("\tBroadcast Address: " + address.Broadcast)); if (address.Destination != null) Console.WriteLine(("\tDestination Address: " + address.Destination)); } Console.WriteLine(); }
private static PacketCommunicator OpenOfflineDevice(int numPackets, Packet packet, TimeSpan intervalBetweenPackets, string dumpFilename, string readFilename = null) { IPacketDevice device = GetOfflineDevice(numPackets, packet, intervalBetweenPackets, dumpFilename, readFilename); PacketCommunicator communicator = device.Open(); try { MoreAssert.AreSequenceEqual(new[] { DataLinkKind.Ethernet }.Select(kind => new PcapDataLink(kind)), communicator.SupportedDataLinks); Assert.AreEqual(DataLinkKind.Ethernet, communicator.DataLink.Kind); Assert.AreEqual("EN10MB (Ethernet)", communicator.DataLink.ToString()); Assert.AreEqual(communicator.DataLink, new PcapDataLink(communicator.DataLink.Name)); Assert.IsTrue(communicator.IsFileSystemByteOrder); Assert.AreEqual(PacketCommunicatorMode.Capture, communicator.Mode); Assert.IsFalse(communicator.NonBlocking); Assert.AreEqual(PacketDevice.DefaultSnapshotLength, communicator.SnapshotLength); Assert.AreEqual(2, communicator.FileMajorVersion); Assert.AreEqual(4, communicator.FileMinorVersion); return(communicator); } catch (Exception) { communicator.Dispose(); throw; } }
// Returns a human readable string containing information about a given device public static string DeviceInformation(this IPacketDevice ipd) { var sb = new StringBuilder(); sb.AppendLine(ipd.Name); if (ipd.Description != null) { sb.Append("\tDescription: ").AppendLine(ipd.Description); } sb.Append("\tLoopback: ").AppendLine((ipd.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback ? "yes" : "no"); foreach (DeviceAddress address in ipd.Addresses) { sb.Append($"\tAddress Family: ").AppendLine(address.Address.Family.ToString()); if (address.Address != null) { sb.Append("\tAddress: ").AppendLine(address.Address.ToString()); } if (address.Netmask != null) { sb.Append("\tNetmask: ").AppendLine(address.Netmask.ToString()); } if (address.Broadcast != null) { sb.Append("\tBroadcast Address: ").AppendLine(address.Broadcast.ToString()); } if (address.Destination != null) { sb.Append("\tDestination: ").AppendLine(address.Destination.ToString()); } } return(sb.ToString()); }
private static void printInterfaceInfo(IPacketDevice pDevice) { foreach (DeviceAddress address in pDevice.Addresses) { if (address.Address != null & address.Address.Family.Equals(SocketAddressFamily.Internet)) { Console.WriteLine("\tAddress: " + address.Address); } } }
// Print device information private static void DevicePrint(IPacketDevice device) { // Name Console.WriteLine(device.Name); // Description if (device.Description != null) { Console.WriteLine("\tDescription: " + device.Description); } else { Console.WriteLine("\tDescription: NONE AVAILABLE"); } // Loopback Address Console.WriteLine("\tLoopback: " + (((device.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback) ? "yes" : "no")); // IP Addresses foreach (DeviceAddress address in device.Addresses) { Console.WriteLine("\tAddress Family: " + address.Address.Family); if (address.Address != null) { Console.WriteLine("\tAddress: " + address.Address); } if (address.Netmask != null) { Console.WriteLine("\tNetmask: " + address.Netmask); } if (address.Broadcast != null) { Console.WriteLine("\tBroadcast Address: " + address.Broadcast); } if (address.Destination != null) { Console.WriteLine("\tDestination Address: " + address.Destination); } } Console.WriteLine(); }
private void PrintFullInformationAboutDevice(IPacketDevice device) { if (device.Description != null) { Console.WriteLine($"\tDescription: {device.Description}"); } Console.WriteLine($"\tLoopback: " + (((device.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback) ? "yes" : "no")); Console.WriteLine(); foreach (DeviceAddress address in device.Addresses) { if (address.Address != null) { Console.WriteLine($"\tAddress Family: {address.Address.Family}"); Console.WriteLine($"\tAddress: {address.Address}"); } if (address.Netmask != null) { Console.WriteLine($"\tNetmask: {address.Netmask}"); } if (address.Broadcast != null) { Console.WriteLine($"\tBroadcast: {address.Broadcast}"); } if (address.Destination != null) { Console.WriteLine($"\tDestination: {address.Destination}"); } Console.WriteLine(); } }
private void SelectButtonClick(object sender, RoutedEventArgs e) { SelectedDevice = (IPacketDevice) interfacesComboBox.SelectedItem; DialogResult = true; Close(); }
public void open(IPacketDevice device) { if (null != device) { PacketCommunicator pc = device.Open(65536, PacketDeviceOpenAttributes.None, 1000); pc.SetFilter("ip and tcp and port " + PortNumbers.BNCSPort.ToString()); comm.Communicator = pc; } else { comm.Communicator = null; } }
// Print all the available information on the given interface private void DevicePrint(IPacketDevice device) { // Name DeviceInfo.Items.Add(device.Name); // Description if (device.Description != null) DeviceInfo.Items.Add(" Description: " + device.Description); // Loopback Address DeviceInfo.Items.Add(" Loopback: " + (((device.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback) ? "yes" : "no")); // IP addresses foreach (DeviceAddress address in device.Addresses) { DeviceInfo.Items.Add(" Address Family: " + address.Address.Family); if (address.Address != null) DeviceInfo.Items.Add(("\tAddress: " + address.Address)); if (address.Netmask != null) DeviceInfo.Items.Add(("\tNetmask: " + address.Netmask)); if (address.Broadcast != null) DeviceInfo.Items.Add(("\tBroadcast Address: " + address.Broadcast)); if (address.Destination != null) DeviceInfo.Items.Add(("\tDestination Address: " + address.Destination)); } }
private void SelectInterfaceExecuted(object sender, ExecutedRoutedEventArgs e) { Effect = new BlurEffect(); BeginStoryboard((Storyboard)Resources["blurElement"]); var selectInterfaceDialog = new SelectInterfaceDialog(); var showDialog = selectInterfaceDialog.ShowDialog(); if (showDialog != null && showDialog.Value) { _selectedDevice = selectInterfaceDialog.SelectedDevice; SelectedInterface.Inlines.Clear(); SelectedInterface.Inlines.Add(new Run("Capture will start on ")); SelectedInterface.Inlines.Add(new Run(_selectedDevice.Description) { FontWeight = FontWeights.Bold }); } capturedPacketsListBox.DataContext = Captured; BeginStoryboard((Storyboard)Resources["sharpenElement"]); Effect = null; e.Handled = true; }