Пример #1
0
        /// <summary>
        /// Provides the description from the system for the inputted device
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public String ProvideCaptureDeviceDescription(LivePacketDevice device = null)
        {
            // if the device is valid
            if (device != null)
            {
                return(LivePacketDeviceExtensions.GetNetworkInterface((LivePacketDevice)device).Description);
            }

            return("No available Description.");
        }
Пример #2
0
        /*
         * Function that will list network interface descriptions in the combo box drop down
         *
         */
        private void ListNetworkInterfaces(int numTries = 5)
        {
            //Detect all interfaces
            allLivePacketDevices = LivePacketDevice.AllLocalMachine;
            string descript = "";

            string inactiveFormat = "{0,27} | {1}";   // format for interfaces that are not currently active
            string activeFormat   = "* {0,17} | {1}"; // format for interfaces that are actively transmitting packets
            string Format         = inactiveFormat;

            //Try the allotted number of times if no interfaces detected
            if (allLivePacketDevices.Count == 0)
            {
                if (numTries > 0)
                {
                    ListNetworkInterfaces(--numTries);
                }
            }

            // Describe each network interface
            for (int i = 0; i < allLivePacketDevices.Count; ++i)
            {
                // Determine the network interface for this interface
                LivePacketDevice livePacketDevice = allLivePacketDevices[i];
                NetworkInterface nic = LivePacketDeviceExtensions.GetNetworkInterface(livePacketDevice);

                string address = "";
                // Query system for description
                descript = nic.Description;

                if (nic != null)
                {
                    // Gather the unique ip properties of this interface
                    IPInterfaceProperties ipprops = nic.GetIPProperties();
                    UnicastIPAddressInformationCollection unicast = ipprops.UnicastAddresses;

                    string lpdAddr = "";
                    string nicAddr = "";

                    // search the interfaces IP addresses for it's IPv4 address
                    foreach (UnicastIPAddressInformation uni in unicast)
                    {
                        nicAddr = uni.Address.ToString();

                        foreach (DeviceAddress addr in livePacketDevice.Addresses)
                        {
                            if (!addr.Address.ToString().Contains("Internet6"))
                            {
                                string[] ipv4addy = addr.Address.ToString().Split();
                                lpdAddr = ipv4addy[1];
                            }

                            if (nicAddr == lpdAddr)
                            {
                                address = nicAddr;
                                //needs tuning so active device will be default shown


                                // Format the description according to activity level
                                Format = inactiveFormat;
                                if (nic.OperationalStatus == OperationalStatus.Up)
                                {
                                    Format = activeFormat;
                                    //  ++activeIndex;
                                }
                            }
                        }
                    }
                }

                descript = String.Format(Format, address, descript);
                cmbInterfaces.Items.Add(descript);
            }
        }
Пример #3
0
 public void GetNetworkInterfaceNullTest()
 {
     Assert.IsNotNull(LivePacketDeviceExtensions.GetNetworkInterface(null));
     Assert.Fail();
 }