ping_list.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python
import sys, os
import urllib2
def get_domains(fname):
domains = []
with open(fname, 'r') as f:
for line in f.readlines():
line = line.strip()
domains.append(line)
return domains
def main():
argc = sys.argv.__len__()
argv = sys.argv
if argc < 2:
print "Supply the filename (domains list)"
return
domains = get_domains(argv[1])
up_num = 0
for hostname in domains:
response = os.system("ping -c 1 " + hostname)
if response == 0:
up_num =+ 1
print "number of active hosts : " + str(up_num)
if __name__ == "__main__":
sys.exit(main())