In this section, i will show you how to create a python3 script, which will ping and display all hosts in a subnet we provide.

Make sure you have installed python3.

$ apt install python3
#import the modules required for this script
import subprocess
import ipaddress
from subprocess import Popen, PIPE
subnet = input("Please enter the network: ")
network = ipaddress.ip_network(subnet)
for i in network.hosts():
    toping = subprocess.Popen(['ping', '-c', '3', i], stdout=PIPE)
    output = toping.communicate()[0]
    hostalive = toping.returncode
    if hostalive == 0:
        print(i, 'is reachable')
       print(i, 'is down')

You can download the script from Here