vik-y
9/13/2016 - 9:04 AM

Script to check if a given host is online or not

Script to check if a given host is online or not

'''
Author: Vikas Yadav

Description:
Script to check if a given host is online or not
This will not work if the given host is blocking ping requests.
'''
import os
import re
import time

# Takes IP of the target as an argument 
# Returns true if the given IP is online
# False otherwise.
def online(IP):
	temp = os.popen("ping -c 1 -W 5 %s" %(IP)).read()
	print temp
	result = re.search("Unreachable", temp)
	if result:
		return False
	else:
		return True


while 1:
	IP = "Enter IP Here"
	if online(IP):
		os.system('notify-send "Target is online" --urgency=critical')
	time.sleep(10)