private static Win32.IP_ADAPTER_INDEX_MAP GetInterfaceMap(uint interfaceIndex) { Win32.IP_INTERFACE_INFO info = GetInterfaceInfo(); foreach (Win32.IP_ADAPTER_INDEX_MAP map in info.Adapters) { if (map.Index == interfaceIndex) { return(map); } } throw new ArgumentOutOfRangeException(nameof(interfaceIndex)); }
/// <summary> /// Renews the lease on the IPv4 address previously obtained through Dynamic Host Configuration Protocol (DHCP) on all interfaces. /// </summary> public static bool RenewDhcpAddress() { bool hasErrors = false; Win32.IP_INTERFACE_INFO info = GetInterfaceInfo(); foreach (Win32.IP_ADAPTER_INDEX_MAP map in info.Adapters) { if (!IpRenewAddress(map)) { hasErrors = true; } } return(hasErrors); }