Linux for network engineers lab 10 of 14

Python network checks: sockets, subprocess and requests

You write Python tools that tell open from closed from filtered, parse ping, read a JSON health page and log in to a router, then join them into a parallel monitor with a proper exit code.

Run this lab

It needs Lite: its 3 nodes are set to 3 vCPU and 2,048 MB in total. That fits the free demo too.

In your workspace: Shared, then Linux for network engineers guided labs, then 10 - Python network checks - sockets subprocess and requests

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

Level
Intermediate
Time
About 75 minutes
Nodes need
3 vCPU, 2,048 MB
Smallest plan
Lite

The scenario

The Halifax team's Bash checks from Lab 09 have outgrown themselves. They want a monitor that handles errors properly, reads a JSON health page and can talk to routers. You'll write it in Python on WS, one small module at a time, and test each against the depot's tracker server WEB and router R1. WS already has requests, netmiko and yaml installed.

DeviceInterfaceAddressRole
WSeth010.10.10.50/24your workstation; write code in /root/lab
R1Gi0/0, Gi0/110.10.10.1/24, 10.10.20.1/24router; user ops, SSH
WEBeth010.10.20.10/24HTTP on 80, /cgi-bin/health returns JSON; port 8443 is blocked by policy
DeviceRunsHow to log in
WSUbuntu 22.04 desktop containerIts console is a remote desktop: root / eve. Open a terminal there.
R1Cisco IOSv 15.9The console opens at >; enable has no password.
WEBAlpine Linux 3.16 with iptables and iproute2Opens on a menu: press 5, then Enter, for a root shell.

What you’ll practise

  • Test TCP ports with sockets and handle each failure
  • Run commands with subprocess and parse the output
  • Call a JSON web service with requests
  • Read a router with netmiko
  • Run checks in parallel and report in JSON with an exit code

The tasks

  1. Start the Linux nodes
  2. A port checker with sockets
  3. Run ping from Python
  4. Call a web service with requests
  5. Ask a router with netmiko
  6. Put it together

The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.

Topology and devices

The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.

Topology of Python network checks - sockets subprocess and requests3 nodes, 2 links. Every link is listed as text below the diagram.WSR1WEBeth0Gi0/0Gi0/1eth0
3 nodes, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Python network checks: sockets, subprocess and requests, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
WSEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB
R1Cisco IOSvvios-adventerprisek9-m.spa.159-3.m91 vCPU, 512 MB
WEBAlpine WAN emulatorclbalpinewanem-alpine-3-16-2-wanem1 vCPU, 512 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Linux for network engineers guided labs.

  3. Open 10 - Python network checks - sockets subprocess and requests and start its nodes, then open Lab Tasks for the scenario and the steps.

The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.

More Linux for network engineers labs

All Linux for network engineers labs

Related labs in other courses

CloudLabBox is independent of Cisco, CompTIA, the Linux Foundation and the Linux Professional Institute. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.