Skip to content

Instantly share code, notes, and snippets.

@zikrillah
Created November 27, 2016 01:33
Show Gist options
  • Save zikrillah/0f637b973655cc0b5e7ed47b47670d15 to your computer and use it in GitHub Desktop.
Save zikrillah/0f637b973655cc0b5e7ed47b47670d15 to your computer and use it in GitHub Desktop.
import ipaddress
from subprocess import Popen, PIPE
net4 = ipaddress.ip_network('10.1.1.0/24')
for x in net4.hosts():
x = str(x)
hostup = Popen(["ping", "-c1", x], stdout=PIPE)
output = hostup.communicate()[0]
val1 = hostup.returncode
if val1 == 0:
print(x, "active")
else:
print(x, "inactive")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment