Created
November 29, 2016 12:36
-
-
Save opi/6374d4a4bcbeb984ba923c80744304bb to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import urllib.request | |
import urllib.error | |
# Free mobile credentials | |
free_user = "XXX" | |
free_pass = "XXX" | |
# Website to ping | |
sites = [ | |
"https://google.com", | |
"https://example.com", | |
] | |
# Send SMS message using free mobile API | |
def send_sms(msg): | |
try: | |
r = urllib.request.urlopen('https://smsapi.free-mobile.fr/sendmsg?user=%s&pass=%s&msg=%s' % (free_user, free_pass, msg)) | |
if r.getcode() != 200: | |
print('-> [x] error sending sms. httpcode: {}', r.getcode()) | |
else: | |
print('-> sms sent : %s' % msg) | |
except: | |
e = sys.exc_info()[0] | |
print(str(e)) | |
# Ping an url | |
def check_site(url): | |
print("Checking availability of %s" % url) | |
try: | |
o = urllib.request.urlopen(url, timeout=120) | |
if o.getcode() != 200: | |
print('-> [-] site is down /o\\') | |
send_sms("%s: Site is down" % url) | |
else: | |
print('-> [+] site is up!') | |
except Exception as e: | |
# https://docs.python.org/3/library/urllib.error.html#urllib.error.URLError | |
print('-> [x] Error occurred while checking site availability: %s' % e) | |
send_sms("%s: Error occurred while checking site availability : %s" % (url, e)) | |
for s in sites: | |
check_site(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment