Created
September 13, 2016 09:04
-
-
Save vik-y/6b956f9b16b3bf3837f6640266c0843f to your computer and use it in GitHub Desktop.
Script to check if a given host is online or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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