using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net.NetworkInformation;

namespace Access_Control_Server
{
    public partial class FormNetworkInfo : Form
    {
        NetworkInterface[] networkInterfaces;

        public FormNetworkInfo()
        {
            InitializeComponent();
        }

        private void getAdapters() {
            networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

            foreach (NetworkInterface adapter in networkInterfaces)
            {
                comboBoxNetworkAdapter.Items.Add(adapter.Description);
            }
            if (comboBoxNetworkAdapter.Items.Count > 0)
                comboBoxNetworkAdapter.SelectedIndex = 0;
        }

        private void formLoad(object sender, EventArgs e)
        {
            getAdapters();
        }

        private void selectionChanged(object sender, EventArgs e)
        {
            NetworkInterface adapter = networkInterfaces[comboBoxNetworkAdapter.SelectedIndex];
            UnicastIPAddressInformationCollection addresses;
            textBoxStatus.Text = adapter.OperationalStatus.ToString();
            textBoxMac.Text = adapter.GetPhysicalAddress().ToString();

            addresses = adapter.GetIPProperties().UnicastAddresses;

            if (addresses.Count > 0)
            {
                textBoxIP.Text = addresses[addresses.Count - 1].Address.ToString();
            }
            else textBoxIP.Text = "";

            if (adapter.GetIPProperties().GatewayAddresses.Count > 0)
            {
                textBoxGatewayIP.Text = adapter.GetIPProperties().GatewayAddresses[0].Address.ToString();
            }
            else textBoxGatewayIP.Text = "";
        }
    }
}
