3
Check that it's possible to establish a http connection against
6
from subprocess import call
7
from argparse import ArgumentParser
9
import urllib.request, urllib.error, urllib.parse
15
Open URL and return True if no exceptions were raised
18
urllib.request.urlopen(url)
19
except (urllib.error.URLError, http.client.InvalidURL):
27
Check HTTP and connection
29
parser = ArgumentParser()
30
parser.add_argument('-u', '--url',
32
default='http://cdimage.ubuntu.com',
33
help='The target URL to try. Default is %(default)s')
34
parser.add_argument('-a', '--auto',
37
help='Runs in Automated mode, with no visible output')
39
args = parser.parse_args()
41
url = {"http": args.url}
44
for protocol, value in url.items():
45
results[protocol] = check_url(value)
47
bool2str = {True: 'Success', False: 'Failed'}
48
message = ("HTTP connection: %(http)s\n"
49
% dict([(protocol, bool2str[value])
50
for protocol, value in results.items()]))
52
command = ["zenity", "--title=Network",
53
"--text=%s" % message]
55
if all(results.values()):
56
command.append("--info")
58
command.append("--error")
64
print("Zenity missing; unable to report test result:\n %s" % message)
66
if any(results.values()):
71
if __name__ == "__main__":