10/34
Sign inSign up free

1028. A Port Check That Tells the Difference

medium 20 XP ~11 minHands-on lab

Before a release, the pipeline checks that every dependency is reachable. The current check prints failed for everything that doesn't connect, so nobody knows whether a hostname is wrong or a service is down.

Task

Create the executable script /home/student/bin/port-check.sh FILE. FILE has one host:port per line (comments start with #, blank lines are ignored). For each target, in order, print one of:

  • open <host>:<port> when a TCP connection succeeds,
  • closed <host>:<port> when the host resolves but the connection fails or takes longer than PORT_TIMEOUT seconds (default 3),
  • unknown <host>:<port> when the host name doesn't resolve,
  • invalid <line> when the line isn't host:port with a port between 1 and 65535.

Exit 0 if every target is open, 1 otherwise. nc and bash's /dev/tcp are available.

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.

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.