Umarudeen
Home / Case studies / Case 04
Case study 04 · Captive portal

Which IPs are actually free?

CompletedProfessional experience2 min read

The short version

I needed the free versus used addresses in a /24 client network without reading a session list by eye. A short script compares the portal's live sessions against the full range and sorts the gaps by IP.

Overview

A captive portal hands out addresses from a /24 client network. When users report they cannot connect, address exhaustion is one of the first things to rule out.

Problem statement

I needed to know quickly how many addresses were free, and which ones, without scanning a long session list by eye.

Approach

  1. Take the used addresses from the portal's live session table.
  2. Compare them with the full address range.
  3. Sort by IP so gaps and exhaustion are obvious at a glance.
shell
# every address in the range, version-sorted
seq 1 254 | sed 's/^/10.0.0./' | sort -V > all.txt
# used addresses from the portal's session table, one per line
<export-session-ips> | sort -V > used.txt
# addresses in all.txt that are not in used.txt
comm -23 all.txt used.txt > free.txt
The example uses a placeholder export command and a generic 10.0.0.0/24 range.

Result

A repeatable script instead of a manual hunt. Sorting is what makes the output usable.

Lessons learned

  • Turn a task you do twice into a script.
  • Version-sort IP addresses (sort -V). Plain text sort puts 10 before 2.

Skills demonstrated

Shell scriptingCaptive portal sessionsCapacity awareness

Confidentiality: all identifying information, credentials, customer data, internal addresses and proprietary configurations have been removed or replaced with illustrative examples.

↑↓ moveEnter openEsc close