Sign inSign up free

1027. Normalize IPv6 Addresses

medium 20 XP ~10 minHands-on lab

Access logs write 2001:DB8:0:0:0:0:0:1, the firewall 2001:db8::1, an old script 2001:0db8:0000::0001. Searching and deduplicating across them is impossible.

Task

Create the executable script /home/student/bin/normalize6.sh that reads one address per line from stdin and prints each in its canonical form (RFC 5952), one per line:

  • lowercase hex, leading zeros removed from each group,
  • the longest run of two or more zero groups replaced with :: (the first one if two runs are equally long); a single zero group stays 0,
  • IPv4-mapped addresses written with the IPv4 part in dotted form: ::ffff:192.0.2.128,
  • a zone (%eth0) is kept as it is.

Lines that aren't IPv6 addresses print INVALID <line>. Empty lines are skipped. Python 3 is installed.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Networking and TLS in Practice. Next step: Plan IPv6 Subnets for a VPC

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.