-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpingListOfDomains.py
More file actions
31 lines (24 loc) · 853 Bytes
/
Copy pathpingListOfDomains.py
File metadata and controls
31 lines (24 loc) · 853 Bytes
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
#Python
#Script goes through a list of URLs from "domains-test" file and pings them to see if the domains are up
import os
home_hostname = "sometestdomain.com"
path="./domains-test"
def open_files_and_return_content(path):
#Open list of files from file:
filename=path
with open(filename) as f:
content = f.readlines()
#You may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
print(content)
return content
def ping_each_hostname(content):
num_content=len(content)
#Run ping through each item of content list
for i in range(num_content):
response = os.system("ping -c 1 " + content["i"])
#and then check the response...
if response != 0:
print(response, 'is up!')
else:
print(response, 'is down!')