예제 #1
0
        // 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();
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        // 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());
        }
예제 #4
0
 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);
         }
     }
 }
예제 #5
0
파일: Program.cs 프로젝트: f1r3-b1rd/NetMon
        // 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();
        }
예제 #6
0
        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();
 }
예제 #8
0
 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;
     }
 }
예제 #9
0
        // 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));
            }
        }
예제 #10
0
        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;
        }