private static bool PeekARP(System.Net.IPAddress adr) { byte[] macAddr = new byte[6]; uint macAddrLen = (uint)macAddr.Length; int Ret = SendARP((int)adr.Address, 0, macAddr, ref macAddrLen); System.Diagnostics.Trace.WriteLine(string.Format("Peeking {0} as {1}", adr.ToString(), Ret)); return(Ret == 0); }
public static PrefixedIPv4Address NextAddress(PrefixedIPv4Address Orig) { System.Net.IPAddress adr = null; System.Diagnostics.Trace.WriteLine("Parsing address" + Orig.Address); if (!System.Net.IPAddress.TryParse(Orig.Address, out adr)) { System.Diagnostics.Trace.WriteLine("Failed with parsing"); return(Orig); } long from = (adr.Address >> 24) & 0xff; long i; /* * if (!PeekARP(adr)) * { // ARP not available - so just guess * i = from + 1; * if (i >= 254) i = 1; * adr.Address = (adr.Address & 0xffffff) | (i << 24); * return new PrefixedIPv4Address() { Address = adr.ToString(), PrefixLength = Orig.PrefixLength }; * }*/ // do ARP scanning, after current for (i = from + 1; i <= 254; i++) { adr.Address = (adr.Address & 0xffffff) | (i << 24); if (!PeekARP(adr)) { break; } } if (i >= 254) { // do ARP scanning, before current for (i = 1; i < from; i++) { adr.Address = (adr.Address & 0xffffff) | (i << 24); if (!PeekARP(adr)) { break; } } // nothing found - just guess if (i >= from) { i = from + 1; if (i >= 254) { i = 1; } adr.Address = (adr.Address & 0xffffff) | (i << 24); } } return(new PrefixedIPv4Address() { Address = adr.ToString(), PrefixLength = Orig.PrefixLength }); }