-
Notifications
You must be signed in to change notification settings - Fork 0
/
PingPy.py
46 lines (36 loc) · 1.49 KB
/
PingPy.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#Author: Dustin Grady
#Function: Ping multiple servers for current status
#Status: In Development
import os
import time
import sys
from subprocess import Popen, PIPE
def printLogo():
print('_____ _ ____ ')
print('| _ \(_)_ __ __ _| _ \ _ _ ')
print('| |_) | | _ \ / _` | |_) | | | |')
print('| __/| | | | | (_| | __/| |_| |')
print('|_| |_|_| |_|\__, |_| \__, |')
print(' |___/ |___/ ')
print(' Author: Dustin Grady')
#Get server names from listOfServers.txt and add them to a list
with open('testServers.txt') as server:
serverNames = server.readlines()
#and then check the response...
def checkResponse():
for i in range (0, len(serverNames)):#Itterate through the server names
#response = os.system("ping -c 1 " + serverNames[i])#Get new response from host
proc = Popen(['ping', '-c1', serverNames[i].strip()], stdout = PIPE, stderr = PIPE)
proc.communicate()#Wait for process to terminate
response = proc.returncode
#print(serverNames[i])#Testing
#print(response)#Testing
if response != 0:
print(serverNames[i].strip() + ' seems to be down')#Strip /n for formatting
else:
print(serverNames[i].strip() + ' seems to be up')
while True:
printLogo()
checkResponse()#Call check response method infinitely
time.sleep(2)#Wait a couple of seconds before refreshing again
os.system('clear')#Clear the console