In this topic we will use client-server applications for our example as they are the most common type of application that exist on the Internet. Client-server communication works where one application (the server) listens on a particular port and on a particular IP address on the computer it's running on, while another application (the client) does almost the same, only that it doesn't listen instead it initiates the connection and tries to reach the listening port on the server.
In this example, I explored another approach to using Finditer to count network interfaces in my last post. I recommend you check that out first before going through this one.
Here I combined re.finditer() with defaultdict() instead, keeping the matched patterns associated with the keyword we are looking for.
Still using the same example data that I've been using in my previous Network Automation examples, this time around I try out a counting scenario.
In this example, I wanted a quick and easy way to just zip through the text and count how many interfaces of a certain type I will find.
I'm using the re.finditer() function to give me an iterable of all matches (line 16).
Have you ever encountered a situation wherein you did a continuous ping to a network device and saw packet loss, but did another continuous ping through it towards a device behind it and saw no packet loss? This can be a more common scenario in network troubleshooting than you might think.
Let's look at the below example diagram.