Created
February 24, 2016 21:19
-
-
Save professorjamesmoriarty/084c86f2f7e8ac24561e 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 | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# | |
# Copyright © 2016 Johnathan "Shaggytwodope" Jenkins <[email protected]> | |
# | |
# Distributed under terms of the MIT license. | |
""" | |
Tool to check if online, returns exit status 0 if succesful or 1 if not. | |
""" | |
import urllib.request | |
import sys | |
def connected(host='http://google.com'): | |
try: | |
urllib.request.urlopen(host) | |
return True | |
except: | |
return False | |
if connected(): | |
print('connected') | |
sys.exit(0) | |
else: | |
print('no connection') | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment