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
#!/usr/bin/python
#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():
    i=str(i)
    toping = subprocess.Popen(['ping', '-c', '3', i], stdout=PIPE)
    output = toping.communicate()[0]
    hostalive = toping.returncode
    if hostalive == 0:
        print(i, 'is reachable')
    else:
       print(i, 'is down')

You can download the script from Here