Skip to content

Instantly share code, notes, and snippets.

@vik-y
Created September 13, 2016 09:04
Show Gist options
  • Save vik-y/6b956f9b16b3bf3837f6640266c0843f to your computer and use it in GitHub Desktop.
Save vik-y/6b956f9b16b3bf3837f6640266c0843f to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment