Sign inSign up free

1020. Is This IP in One of These Networks?

medium 20 XP ~9 minHands-on lab

The deploy script only lets requests through from allowed networks. Its current check compares string prefixes, so 10.10.0.1 "matched" 10.1.0.0/16.

Task

Create the executable script /home/student/bin/in-cidr.sh IP CIDR... that exits:

  • 0 if IP is inside at least one of the networks,
  • 1 if it is in none of them,
  • 2 if IP or any CIDR is invalid, or no CIDR is given. A network with host bits set (like 10.0.0.1/8) is invalid.

It must work for IPv4 and IPv6. An address is never inside a network of the other family. 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: Carve Subnets Out of an Address Block

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.