Log the IP version (IPv4/IPv6)

Identify which type of IP address was used by the client connecting to your Fastly service.

VCL

Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):

Compute@Edge

Use this solution in your Compute@Edge service:

  1. Rust
#[fastly::main]
fn main(req: Request) -> Result<Response, Error> {
log_fastly::init_simple("mylogs", log::LevelFilter::Info);
let client_ip = req.get_client_ip_addr().unwrap();
log::info!(
"client_ip={} is {}",
client_ip.to_string(),
four_or_six(client_ip)
);
Ok(Response::new())
}
fn four_or_six(ip: IpAddr) -> String {
match ip.is_ipv4() {
true => "IPv4".to_string(),
false => "IPv6".to_string(),
}
}