Testing for reachability

Often, the first step of troubleshooting is to conduct a small reachability test. For network engineers, ping is our best friend when it comes to network reachability tests. It is a way to test the reachability of a host on an IP network by sending a small package across the network to the destination.

We can automate the ping test via the OS module or the subprocess module:

>>> import os>>> host_list = ['www.cisco.com', 'www.google.com']>>> for host in host_list:...     os.system('ping -c 1 ' + host)...PING e2867.dsca.akamaiedge.net (69.192.206.157) 56(84) bytes of data.64 bytes from a69-192-206-157.deploy.static.akamaitechnologies.com (69.192.206.157): icmp_seq=1 ttl=54 time=14.7 ms--- e2867.dsca.akamaiedge.net ping ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.