private void Window_Loaded(object sender, RoutedEventArgs e) { IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName()); comboBox2.Items.Clear(); if (ips.Length > 0) foreach (IPAddress ipadd in ips) { if (ipadd.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { comboBox2.Items.Add(ipadd.ToString()); } } if (ips.Length > 0) comboBox2.SelectedIndex = 0; CaptureDeviceList allDevices = SharpPcap.CaptureDeviceList.Instance; foreach(ICaptureDevice dev in allDevices) { Device cdev = new Device(); cdev.DisplayName = dev.Description; cdev.CaptureDevice = dev; comboBox1.Items.Add(cdev); } if (comboBox1.Items.Count > 0) comboBox1.SelectedIndex = 0; }
private void button1_Click(object sender, RoutedEventArgs e) { currentDev = (Device)comboBox1.SelectedItem; currentDev.CaptureDevice.Open(); byte[] srcMacBytes = currentDev.CaptureDevice.MacAddress.GetAddressBytes(); string localMAC = BitConverter.ToString(srcMacBytes).Replace("-", ":"); textBox1.Text = localMAC; textBox2.Text = localMAC; comboBox1.IsEnabled = false; button3.IsEnabled = true; button1.IsEnabled = false; }