/// <inheritdoc/> protected override void ProcessRecord() { foreach (var input in InputObject) { if (input.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork) { WriteError(new ErrorRecord( new PSArgumentException("The address provided is not an IPv4 address (address family is not InterNetwork)."), "InvalidAddressFamily", ErrorCategory.InvalidArgument, input) { ErrorDetails = new ErrorDetails($"The IP address '{input}' is not an IPv4 address. Only IP addresses " + $"in the {System.Net.Sockets.AddressFamily.InterNetwork} address family can be converted by this cmdlet.") { RecommendedAction = "Only provide IPv4 addresses." } } ); } else { WriteObject(IPv4TypeConverter.ConvertIPv4ToNumber(input)); } } }
/// <summary> /// Converts an IP address the associated <see cref="long"/> value. /// </summary> /// <param name="ipAddress">The address to be converted.</param> /// <returns>The <see cref="long"/> value representation of <paramref name="ipAddress"/>.</returns> public static long ToLong(this IPAddress ipAddress) => IPv4TypeConverter.ConvertIPv4ToNumber(ipAddress);