import subprocess
import ipaddress

net_addr = input("Enter a network address in CIDR format(ex.192.168.1.0/24): ")
ip_net = ipaddress.ip_network(net_addr)

all_hosts = list(ip_net.hosts())

info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

for i in range(len(all_hosts)):
    output = subprocess.Popen(['ping', '-n', '1', '-w', '500', str(all_hosts[i])], stdout=subprocess.PIPE, startupinfo=info).communicate()[0]
    
    if "Destination host unreachable" in output.decode('utf-8'):
        print(str(all_hosts[i]), "is DOWN")
    elif "Request timed out" in output.decode('utf-8'):
        print(str(all_hosts[i]), "is DOWN")
    else:
        print(str(all_hosts[i]), "is UP")




