
This project shows you how to use the Python Os Module to send a Ping Command and then write the results to a basic HTML Dashboard. We have a Host List of FQDN’s and IP Addresses that we send a single ping to in a continuous loop. The results of the ping command are printed to the console screen, and written to the HTML file.
The HTML page is set to auto refresh every 4 seconds, and so when each loop is finsihed in the Python script the results will be displayed on the web page.

import os
from time import sleep
host = ["192.168.1.20", "192.168.1.100","salesforce.com", "google.com", "cisco.com"]
pause = 10
header = f"<meta http-equiv='refresh' content='4'> <title>Up/ Down App</title> <h1>Network Monitor</h1>"
while True:
body = ""
for x in host:
command = f"ping -c 1 {x}"
response = os.popen(command)
response = response.read()
print(response)
body = f"{body} {x}<br><pre>{response}</pre><br>"
html = f"{header} {body}"
file = open("network.html", "w")
file.write(html)
file.close()
print("*******")
sleep(pause)
Code language: Python (python)