private void BlockConnection(PhysicalAddress mac, System.Net.IPAddress addr) { Guid InterfaceGuid = WlanMgr.HostedNetworkGuid; if (!Properties.Settings.Default.Whitelist.Contains(mac.ToString())) { PhysicalAddress macaddr = mac.Reverse(); IPhlpapi.SetIpNetEntry(InterfaceGuid, macaddr, addr); Invoke(new Action(() => UpdateBlacklistItems(mac))); Trace.WriteLine($"Blocked: IP: {addr} MAC: {mac}"); } else { Invoke(new Action(() => UpdateWhitelistItems(mac))); Trace.WriteLine($"Allowed: IP: {addr} MAC: {mac}"); } }
private void OnCellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex.Equals(6)) { string mac = DataGridList.Rows[e.RowIndex].Cells[1].Value as string ?? string.Empty; string ip = DataGridList.Rows[e.RowIndex].Cells[2].Value as string ?? string.Empty; mac = mac.Replace(':', '-'); if (System.Net.IPAddress.TryParse(ip, out System.Net.IPAddress address)) { PhysicalAddress macaddr = PhysicalAddress.Parse(mac); switch ((int)DataGridList.Rows[e.RowIndex].Cells[6].Tag) { case 0: DataGridList.Rows[e.RowIndex].Cells[6].Value = "Block"; DataGridList.Rows[e.RowIndex].Cells[6].Tag = 1; IPhlpapi.SetIpNetEntry(WlanMgr.HostedNetworkGuid, macaddr, address); Trace.WriteLine("Allowed: IP: " + ip + " MAC: " + macaddr.ToString()); do { Properties.Settings.Default.Blacklist.Remove(macaddr.ToString()); }while (Properties.Settings.Default.Blacklist.Contains(macaddr.ToString())); Properties.Settings.Default.Whitelist.Add(macaddr.ToString()); Properties.Settings.Default.Save(); break; case 1: PhysicalAddress bmacaddr = macaddr.Reverse(); DataGridList.Rows[e.RowIndex].Cells[6].Value = "Allow"; DataGridList.Rows[e.RowIndex].Cells[6].Tag = 0; IPhlpapi.SetIpNetEntry(WlanMgr.HostedNetworkGuid, bmacaddr, address); Trace.WriteLine("Blocked: IP: " + ip + " MAC: " + macaddr.ToString()); do { Properties.Settings.Default.Whitelist.Remove(macaddr.ToString()); }while (Properties.Settings.Default.Whitelist.Contains(macaddr.ToString())); Properties.Settings.Default.Blacklist.Add(macaddr.ToString()); Properties.Settings.Default.Save(); break; } } } }