OpenCyber Academy
Rapid course · Lesson 10 · English
Course code: OCA-018Lesson 10: OCA-018-A010

400 is why that address fails

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Lesson map

Lesson 10. Map, example, EX056.

flowchart TD
  V["198.51.100.400"] --> P["ip_address raises"]
  P --> D{"Digits only after dots are removed?"}
  D -->|Yes| I["print invalid and skip"]
  G["203.0.113.9"] --> OK["ip_address accepts"]

One call rejects the broken octet. A different value passes the same call.

Logical drawing

rejected
  198.51.100.400
  octet 400
accepted as an address
  203.0.113.9
not a lookup
  no DNS
  no route

Learning outcomes

After this chapter, you should be able to:

  1. Say which call rejects 198.51.100.400.
  2. Separate that rejection from a domain.
  3. Refuse a network lookup this file does not make.

10.1 The library raises. The digit test then chooses the invalid line.

ipaddress.ip_address accepts 203.0.113.9 and raises ValueError for 198.51.100.400, because 400 is above 255. The except branch then removes dots and asks whether the rest is all digits. 19851100400 is all digits, so the script prints invalid: and does not append the pair. A domain fails the address call too, but the leftover characters are not all digits, so the domain is appended instead of rejected. The digit test is how this file tells a broken address from a name. It is not a reputation check.

The header of the book already limits addresses to documentation ranges. 203.0.113.9 parses and sits in such a range. 198.51.100.400 does not parse, so it is not a host in 198.51.100.0/24. The script never asks the network which of them exists. There is no DNS call in lab_rapid.py. Visiting either name is outside the lab, and this chapter does not add a lookup.

Lesson table; scroll horizontally to read all columns →

Value Branch
203.0.113.9 Accepted by ip_address
198.51.100.400 Raised, then classified invalid
A domain with letters Raised, then appended
A DNS answer Not requested

10.2 Worked example

Lesson table; scroll horizontally to read all columns →

Offered claim What the branch did Decision
"400 cannot be an octet, so the line says invalid." The raise plus the digit test Keep
"203.0.113.9 is kept by the same call." No exception Keep
"The script resolved the name." No DNS call Refuse
"The invalid address is a domain because it failed." The digit test separated it Refuse

Synthetic case. Both values are classroom literals.

Errors and limits

Do not go and look the rejected value up.

Apply

  • EX056 — The octet. Why is 198.51.100.400 invalid while 203.0.113.9 is kept, and does the script query DNS?
    Show marking criteria
    Rubric: 3 = 400 is above 255 so ip_address raises; the digit test prints invalid and skips; 203.0.113.9 parses; there is no DNS call;; 2 = the octet fails and the other address parses;; 1 = one value;; 0 = none.
Worked answers

EX056. 400 is above 255, so ip_address raises, the digit test prints invalid, and the pair is skipped. 203.0.113.9 parses. The script makes no DNS call.