<a id="ch-10"></a>

## Chapter 10 — 400 is why that address fails

<!-- open-cyber-academy:lesson-figures:start ch-10 -->
### Lesson map

Lesson 10. Map, example, EX056.

```mermaid
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

```text
rejected
  198.51.100.400
  octet 400
accepted as an address
  203.0.113.9
not a lookup
  no DNS
  no route
```
<!-- open-cyber-academy:lesson-figures:end ch-10 -->

### 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.

| 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

| 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? *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.

<!-- open-cyber-academy:chapter-navigation:start ch-10 -->
### Continue studying — lesson 10 (chapter 10 of 20)

[← Chapter 09](#ch-09) · [Course chapter index](../SUBJECTS.md) · [Chapter 11 →](#ch-11)

Continue to the next authored lesson.
<!-- open-cyber-academy:chapter-navigation:end -->

## Worked answers

<a id="answer-ex056"></a>
**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.
