/usr/lib/plainbox-provider-checkbox/bin/network_check is in plainbox-provider-checkbox 0.25-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #!/usr/bin/env python3
"""
Check that it's possible to establish a http connection against
ubuntu.com
"""
from subprocess import call
from argparse import ArgumentParser
import http.client
import urllib.request, urllib.error, urllib.parse
import sys
def check_url(url):
"""
Open URL and return True if no exceptions were raised
"""
try:
urllib.request.urlopen(url)
except (urllib.error.URLError, http.client.InvalidURL):
return False
return True
def main():
"""
Check HTTP and connection
"""
parser = ArgumentParser()
parser.add_argument('-u', '--url',
action='store',
default='http://cdimage.ubuntu.com',
help='The target URL to try. Default is %(default)s')
parser.add_argument('-a', '--auto',
action='store_true',
default=False,
help='Runs in Automated mode, with no visible output')
args = parser.parse_args()
url = {"http": args.url}
results = {}
for protocol, value in url.items():
results[protocol] = check_url(value)
bool2str = {True: 'Success', False: 'Failed'}
message = ("HTTP connection: %(http)s\n"
% dict([(protocol, bool2str[value])
for protocol, value in results.items()]))
command = ["zenity", "--title=Network",
"--text=%s" % message]
if all(results.values()):
command.append("--info")
else:
command.append("--error")
if not args.auto:
try:
call(command)
except OSError:
print("Zenity missing; unable to report test result:\n %s" % message)
if any(results.values()):
return 0
else:
return 1
if __name__ == "__main__":
sys.exit(main())
|