Exemple #1
0
        private void UpdateAddresses(LivePacketDevice iface, DeviceAddress address)
        {
            var interfaceAddress = ((IpV4SocketAddress)address.Address).Address;

            lblInterfaceAddress.Text = interfaceAddress.ToString();

            if (address.Netmask?.Family == SocketAddressFamily.Internet)
            {
                tbNetmask.Text = ((IpV4SocketAddress)address.Netmask).Address.ToString();
            }

            var gateways = iface.GetNetworkInterface().GetIPProperties().GatewayAddresses;

            foreach (var gateway in gateways)
            {
                if (gateway.Address.AddressFamily == AddressFamily.InterNetwork)
                {
                    tbGatewayIp.Text = gateway.Address.ToString();

                    ShowStatus("resolving MAC address...");
                    cbInterfaces.Enabled = false;

                    Task.Run(() =>
                    {
                        var macAddress = NetworkUtilities.GetMacByIpAddress(iface, _packetCommunicator, interfaceAddress, new IpV4Address(gateway.Address.ToString()), 3000);
                        Invoke((MethodInvoker) delegate
                        {
                            if (macAddress != null)
                            {
                                tbGatewayMac.Text = macAddress.ToString();
                            }

                            HideStatus();
                            cbInterfaces.Enabled = true;
                        });
                    });
                }
            }
        }