Network Automation Engineer

Case File: The Interface Report

Every night someone reads the interface table of forty routers by eye. Teach Python to read one saved 'show ip interface brief' for you: parse the lines, handle the two-word status that breaks a naive split, count what is healthy, list what is shut down on purpose, and find the real faults. The table is generated for you alone.

45 min

Sabi Logistics · Automation 1

The Interface Report

Every morning a person reads the interface tables of forty routers by eye, and last week one broken port was missed

Tunde Night NOC lead · Phone call

Tunde. Every night I log in to our routers one by one, run show ip interface brief, and read the table with my eyes. Forty routers, thirty lines each. Last week I missed a port that had been down for two days, because I was tired and it looked like all the others.

I do not need anything clever. I need a script that reads the saved output and tells me four things: how many interfaces there are, how many are really healthy, which ones somebody shut down on purpose (I do not want to be told about those), and which ones are actually broken. Broken means: it has an IP address, nobody shut it down, and it is not up and up.

I saved one router’s output to a file. Show me you can read it with Python, and then we will do the other thirty-nine.

The brief

What you need to know first.

  • Network devices print text for people. To automate, you turn that text into data (lists and dictionaries) and then ask questions of the data. This is the most common first step in network automation, and you can do it with plain Python and no libraries.
  • The table. show ip interface brief prints one line per interface: name, IP address, OK?, method, status, protocol. The status and the protocol are different things: status is the physical/administrative state of the port, protocol is whether the line protocol works (it needs a signal from the other end). A healthy interface is up/up. administratively down / down means somebody ran shutdown on the port. down/down with an address is usually a cable or the device at the other end. up/down is a layer 2 problem (a mismatch, a keepalive failure).
  • Reading a line. line.split() cuts a line at every run of spaces and gives a list of words. Python lists count from the front (t[0]) and from the back (t[-1]). The name is t[0], the address is t[1], the protocol is t[-1]. The status is everything between the method (t[3]) and the protocol: " ".join(t[4:-1]). That slice is the whole trick, because “administratively down” is two words.
  • Collect rows as dictionaries: rows.append({"name": t[0], "ip": t[1], "status": ..., "proto": t[-1]}). After that, every question is a short loop or a comprehension: [r["name"] for r in rows if r["status"] == "administratively down"], sum(1 for r in rows if ...).
  • Combine conditions carefully: a and b and not (c and d). Write the condition as a sentence first (“has an address, is not shut down, is not up/up”) and then translate it.
  • Skip the header: splitlines()[1:]. Count what you parse (len(rows)) and compare it with the number of lines in the file: if they differ, you lost a line.
  • Write the answers into the variables in the starter (n_interfaces, up_up, admin_down, broken, who_has). The checker reads those variables after your code runs. Lists must be in the order the interfaces appear in the file.

The lab gives you interfaces.txt, generated for you alone. It runs real Python in your browser (about 10 MB the first time, then remembered).

Preparing your data…

On a real system

The lab modelled the rules with a script. These are the commands that you would type on the real thing.

You want toTypeWhat you get
list the interfaces of a Cisco router with their addresses and stateshow ip interface briefone line per interface: address, status and protocol
read the error counters of one interfaceshow interfaces GigabitEthernet0/1input and output errors, CRC and drops since the last reset
list the interfaces on MikroTik RouterOS/interface printname, type, MTU and whether each interface is running

Only run commands on systems that you own or have written permission to test.

🔒 The debrief unlocks when you close the case. Finish the lab above.

Write the note for the night shift

Write the short note that goes with the script: what it reads and what it reports, how it tells a port that was shut down on purpose from a real fault, why splitting on spaces needs care for the status column, how you check that it parsed every line, and what you would try before trusting it on routers of another model.

0 words

🧪 Want to practise this on your own computer? See how to set up your lab →

📝

Knowledge Check

1 of 4

Why does line.split() give a different number of pieces for 'GigabitEthernet0/1 unassigned YES unset administratively down down'?

Report a problem

About: /lessons/case-the-interface-report