Skip to main content

extract_unique_parsed

Function extract_unique_parsed 

Source
pub fn extract_unique_parsed(haystack: &[u8]) -> Result<Vec<IpAddr>>
Expand description

Extract unique IPv4 and IPv6 addresses from input, returning them as parsed IpAddr objects.

Maintains order of first observation (not lexicographic order). This is a convenience function that uses default settings (all IP types included). For more control, use ExtractorBuilder and Extractor::find_iter().

§Errors

Returns an error if the builder fails to initialize (e.g., no IP types selected), or if an extracted address cannot be parsed (should not happen in practice).

§Example

use ip_extract::extract_unique_parsed;

let ips = extract_unique_parsed(b"Server at 192.168.1.1, another at 192.168.1.1")?;
assert_eq!(ips.len(), 1);
assert!(ips[0].is_ipv4());