-
Notifications
You must be signed in to change notification settings - Fork 0
/
isDomainUp.py
47 lines (40 loc) · 1.29 KB
/
isDomainUp.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import time
from datetime import datetime
import argparse
import requests
from requests.exceptions import ConnectionError, ReadTimeout, MissingSchema
from http import HTTPStatus
import sys
parser = argparse.ArgumentParser()
parser.add_argument('-url', help = 'URL to test', required = True)
parser.add_argument('-w', help = 'Seconds to wait before retry', default=30)
args = parser.parse_args()
url = args.url
wait = int(args.w)
connected = False
while not connected:
try:
print('Trying to connect')
print('Time: %s' % (datetime.now()))
print('Domain: %s' % (url))
r = requests.get(url, timeout = 15)
connected = True
except ReadTimeout as e:
print('***** Read Timed Out *****')
print('Trying again in %d seconds' % (wait))
print('*' * 60)
time.sleep(wait)
except ConnectionError as e:
print('***** Connection Error *****')
print('Trying again in %d seconds' % (wait))
print('*' * 60)
time.sleep(wait)
except MissingSchema as e:
print('***** Missing Schema *****')
print(e)
print('Exiting')
sys.exit(1)
statuscode = r.status_code
print('Successfully connected')
print('Status code: %d - %s' % (statuscode, HTTPStatus(statuscode).phrase))