Skip to main content

extract_parsed

Function extract_parsed 

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

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

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_parsed;

let ips = extract_parsed(b"Server at 192.168.1.1 and 2001:db8::1")?;
assert_eq!(ips.len(), 2);
assert!(ips[0].is_ipv4());
assert!(ips[1].is_ipv6());