Python - Check If Server Up or Down
Python Script
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
import os
import time
hostname = "google.com" # #example
response = os.system("ping -c 1 " + hostname + " > /dev/null")
msg_hostup ='''
|-----------------------------------------|
|---Host '''+hostname+''', IS UP !
|-----------------------------------------|
''';
msg_hostdown ='''
|-----------------------------------------|
|---Host '''+hostname+''', Is DOWN !
|-----------------------------------------|
''';
#and then check the response...
while True:
try:
if response == 0:
print msg_hostup
os.system('zenity --display :0 --info --width=250 --height=50 --title "Server Info" --text " Host '+hostname+', is UP !"')
break
else:
os.system('cls' if os.name == 'nt' else 'clear')
#print hostname, 'is down !'
print msg_hostdown
time.sleep(2)
except:
print "Error...!"
break
Post by : Admin.