/// <summary> /// Gets a list of ARP table entries /// </summary> /// <returns>The list of ARP table entries</returns> public List <ARPEntry> GetARPEntries() { List <ARPEntry> arpEntries = new List <ARPEntry>(); try { IPHelperNetTableWrapper dsa = new IPHelperNetTableWrapper(); MIB_IPNETROW[] table = dsa.GetIPNetRows(); for (int index = 0; index < table.Length; index++) { IPAddress ip = new IPAddress(table[index].dwAddr); byte[] macBytes = new byte[] { table[index].mac0, table[index].mac1, table[index].mac2, table[index].mac3, table[index].mac4, table[index].mac5 }; string physicalAddress = string.Join(":", macBytes.Select(s => s.ToString("X2"))); ARPEntry ae = new ARPEntry(); ae.InternetAddress = ip.ToString(); ae.PhysicalAddress = physicalAddress; ae.InterfaceIndex = table[index].dwIndex; arpEntries.Add(ae); } } catch (Exception exc) { MyDebugger.Instance.LogMessage(exc, DebugVerbocity.Exception); } return(arpEntries); }
/// <summary> /// ARP IP matches? /// </summary> /// <param name="IP"></param> /// <param name="entry"></param> /// <returns></returns> private static unsafe bool IPEqual(byte[] IP, ARPEntry entry) { if (entry.IP[0] == IP[0] && entry.IP[1] == IP[1] && entry.IP[2] == IP[2] && entry.IP[3] == IP[3]) { return(true); } return(false); }